Registry / web-framework / django-bootstrap-form

django-bootstrap-form

JSON →
library3.4pypypiunverified

django-bootstrap-form is a Python library that provides simple template tags and filters to render Django forms and fields using Bootstrap 3 markup. It simplifies the integration of Django forms into Bootstrap-themed frontends, helping developers quickly style forms with Bootstrap classes. The current version is 3.4, and it has a stable, albeit irregular, release cadence primarily driven by Django compatibility updates.

pip install django-bootstrap-form
INSTALL
IMPORT
SIG · DJANGO-BOOTSTRAP-F
D
django-bootstrap-form
web-frameworkpythonv3.4
Install
4.4s avg
Import
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.7MB
glibc
py 3.103.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)
Debug
Known issues
gotchaThis library is primarily designed for Bootstrap 3. While it can be used with newer Bootstrap versions (4/5), the generated HTML markup will adhere to Bootstrap 3 conventions, potentially requiring manual CSS adjustments or custom templates for full compatibility.
fix
If targeting Bootstrap 4/5, consider using `django-bootstrap4`, `django-bootstrap5`, or a custom form template for better integration. If using this library, be prepared for minor styling inconsistencies.
affects: All versions
gotchaThe `bootstrap_form` template tags must be loaded at the top of any template where they are used. Forgetting `{% load bootstrap_form %}` will result in a `TemplateSyntaxError`.
fix
Ensure `{% load bootstrap_form %}` is present at the beginning of your Django template file where you intend to use the `bootstrap_form` filter or `bootstrap_field` tag. Also, verify `django_bootstrap_form` is in `INSTALLED_APPS`.
affects: All versions
gotchaThis library focuses exclusively on rendering Django forms and fields with Bootstrap styling. It does not provide components like navigation bars, modals, or other general Bootstrap UI elements.
fix
For comprehensive Bootstrap UI component integration, pair this library with manual HTML/CSS or use a more feature-rich Django Bootstrap integration library that covers a wider range of UI elements.
affects: All versions
Upgrade
Version history
3.4latest on PyPI · released Mar 15, 2018
Audit
Dependencies
DjangorequiredRequired for framework integration and form rendering.
Agent activity
10 hits · last 30 days
node
10
Resources