Install & Compatibility
Where this runs
tested against v3.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.7MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.4s · import 0.000s · 68MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
template tags
✓ {% load bootstrap_form %}
✗ {% load bootstrap4 %}
This library uses `bootstrap_form` for its template tags, not `bootstrap4` or `bootstrap5`, which belong to other integration libraries.
This quickstart demonstrates how to render a Django form using the `bootstrap_form` template filter, or individual fields with `bootstrap_field`. It requires loading the `bootstrap_form` template tags at the top of your template. Ensure `django_bootstrap_form` is added to your Django project's `INSTALLED_APPS` for the tags to be available. The example also includes a Bootstrap 3 CSS link for correct styling.
import os
from django import forms
from django.template import Template, Context
from django.conf import settings
# Minimal Django settings setup for standalone template rendering
# In a real Django project, this is handled by your settings.py
if not settings.configured:
settings.configure(
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
],
'libraries': {
'bootstrap_form': 'django_bootstrap_form.templatetags.bootstrap_form',
}
},
}
],
INSTALLED_APPS=[
'django_bootstrap_form',
'django.contrib.auth',
'django.contrib.contenttypes',
]
)
# Simulate a simple Django form
class MyForm(forms.Form):
name = forms.CharField(label='Your Name', max_length=100)
email = forms.EmailField(label='Your Email')
message = forms.CharField(widget=forms.Textarea, label='Your Message')
subscribe = forms.BooleanField(label='Subscribe to newsletter', required=False)
# Template string demonstrating usage
template_string = '''
{% load bootstrap_form %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Django Bootstrap Form</title>
<!-- Bootstrap 3 CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding: 20px; }
.container { max-width: 600px; }
</style>
</head>
<body>
<div class="container">
<h1>Contact Us</h1>
<form method="post">
{% csrf_token %} <!-- Required in a real Django app -->
{{ form|bootstrap_form }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<hr>
<h2>Individual Field Rendering</h2>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{ field|bootstrap_field }}
{% endfor %}
<button type="submit" class="btn btn-success">Submit Individual</button>
</form>
</div>
</body>
</html>
'''
# Instantiate the form
form_instance = MyForm()
# Create a context for rendering
context = Context({'form': form_instance})
# Render the template
template = Template(template_string)
rendered_html = template.render(context)
# Print the rendered HTML (in a real Django app, this would be returned by a view)
print(rendered_html)
Upgrade
Version history
3.4latest on PyPI · released Mar 15, 2018
Audit
Dependencies
DjangorequiredRequired for framework integration and form rendering.