Template tags and Usage¶
- Add to INSTALLED_APPS in your
settings.py
:
'bootstrap3',
- In your templates, load the
bootstrap3
library and use thebootstrap_*
tags:
{% load bootstrap3 %}
{# Load CSS and JavaScript #}
{% bootstrap_css %}
{% bootstrap_javascript %}
{# Display django.contrib.messages as Bootstrap alerts }
{% bootstrap_messages %}
{# Display a form #}
<form action="/url/to/submit/" method="post" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% bootstrap_icon "star" %} Submit
</button>
{% endbuttons %}
</form>
The ``bootstrap3`` template tag library includes the following template tags:
Note
All the following examples it is understood that you have already loaded the bootstrap3
template tag library, placing the code below in the beginning that each template that bootstrap3
template tag library will be used:
{% load bootstrap3 %}
bootstrap_form¶
Render a form
Tag name:
bootstrap_form
Parameters:
args: kwargs: usage:
{% bootstrap_form form FIXTHIS %}
example:
{% bootstrap_form form FIXTHIS %}
bootstrap_formset¶
Render a formset
Tag name:
bootstrap_formset
Parameters:
args: kwargs: usage:
{% bootstrap_formset formset FIXTHIS %}
example:
{% bootstrap_formset formset FIXTHIS %}
bootstrap_field¶
Render a field
Tag name:
bootstrap_field
Parameters:
args: kwargs: usage:
{% bootstrap_field form_field FIXTHIS %}
example:
{% bootstrap_form form_field FIXTHIS %}
bootstrap_label¶
Render a label
Tag name:
bootstrap_label
Parameters:
args: kwargs: usage:
{% bootstrap_label FIXTHIS %}
example:
{% bootstrap_label FIXTHIS %}
bootstrap_button¶
Render a button
Tag name:
bootstrap_button
Parameters:
args: kwargs: usage:
{% bootstrap_button FIXTHIS %}
example:
{% bootstrap_button FIXTHIS %}
bootstrap_icon¶
Render an icon
Tag name:
bootstrap_icon
Parameters:
icon: icon name usage:
{% bootstrap_icon "icon_name" %}
example:
{% bootstrap_icon "star" %}
buttons¶
Render buttons for form
Tag name:
bootstrap_buttons
Parameters:
parser: token: usage:
{% bootstrap_buttons FIXTHIS %}
example:
{% bootstrap_buttons FIXTHIS %}
bootstrap_messages¶
Show django.contrib.messages Messages in Bootstrap alert containers
Tag name:
bootstrap_messages
Parameters:
context: args: kwargs: usage:
{% bootstrap_messages FIXTHIS %}
example:
{% bootstrap_messages FIXTHIS %}
bootstrap_pagination¶
Render pagination for a page
Tag name:
bootstrap_pagination
Parameters:
page: kwargs: usage:
{% bootstrap_pagination FIXTHIS %}
example:
{% bootstrap_pagination FIXTHIS %}
bootstrap_jquery_url¶
Tag name:
bootstrap_jquery_url
Return the full url to jQuery file to use
Default value:
//code.jquery.com/jquery.min.js
this value is configurable, see Settings section
usage:
{% bootstrap_jquery_url %}
example:
{% bootstrap_jquery_url %}
bootstrap_javascript_url¶
Return the full url to FIXTHIS
Default value:
None
this value is configurable, see Settings section
Tag name:
bootstrap_javascript_url
usage:
{% bootstrap_javascript_url %}
example:
{% bootstrap_javascript_url %}
bootstrap_css_url¶
Return the full url to FIXTHIS
Default value:
None
this value is configurable, see Settings section
Tag name:
bootstrap_css_url
usage:
{% bootstrap_css_url %}
example:
{% bootstrap_css_url %}
bootstrap_css¶
Return HTML for Bootstrap CSS Adjust url in settings. If no url is returned, we don’t want this statement to return any HTML. This is intended behavior.
Default value:
FIXTHIS
this value is configurable, see Settings section
Tag name:
bootstrap_css
usage:
{% bootstrap_css %}
example:
{% bootstrap_css %}
bootstrap_javascript¶
Return HTML for Bootstrap JavaScript Adjust url in settings. If no url is returned, we don’t want this statement to return any HTML. This is intended behavior.
Default value:
None
this value is configurable, see Settings section
Tag name:
bootstrap_javascript
Parameters:
jquery: True to include jquery FIXTHIS usage:
{% bootstrap_javascript FIXTHIS %}
example:
{% bootstrap_javascript FIXTHIS %}