{"id":8089,"library":"django-bootstrap-form","title":"Django Bootstrap Form","description":"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.","status":"active","version":"3.4","language":"en","source_language":"en","source_url":"https://github.com/tzangms/django-bootstrap-form","tags":["django","forms","bootstrap","frontend","template-tags"],"install":[{"cmd":"pip install django-bootstrap-form","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for framework integration and form rendering.","package":"Django","optional":false}],"imports":[{"note":"This library uses `bootstrap_form` for its template tags, not `bootstrap4` or `bootstrap5`, which belong to other integration libraries.","wrong":"{% load bootstrap4 %}","symbol":"template tags","correct":"{% load bootstrap_form %}"}],"quickstart":{"code":"import os\nfrom django import forms\nfrom django.template import Template, Context\nfrom django.conf import settings\n\n# Minimal Django settings setup for standalone template rendering\n# In a real Django project, this is handled by your settings.py\nif not settings.configured:\n    settings.configure(\n        TEMPLATES=[\n            {\n                'BACKEND': 'django.template.backends.django.DjangoTemplates',\n                'DIRS': [],\n                'APP_DIRS': True,\n                'OPTIONS': {\n                    'context_processors': [\n                        'django.template.context_processors.debug',\n                        'django.template.context_processors.request',\n                    ],\n                    'libraries': {\n                        'bootstrap_form': 'django_bootstrap_form.templatetags.bootstrap_form',\n                    }\n                },\n            }\n        ],\n        INSTALLED_APPS=[\n            'django_bootstrap_form',\n            'django.contrib.auth',\n            'django.contrib.contenttypes',\n        ]\n    )\n\n# Simulate a simple Django form\nclass MyForm(forms.Form):\n    name = forms.CharField(label='Your Name', max_length=100)\n    email = forms.EmailField(label='Your Email')\n    message = forms.CharField(widget=forms.Textarea, label='Your Message')\n    subscribe = forms.BooleanField(label='Subscribe to newsletter', required=False)\n\n# Template string demonstrating usage\ntemplate_string = '''\n{% load bootstrap_form %}\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Django Bootstrap Form</title>\n    <!-- Bootstrap 3 CSS -->\n    <link href=\"https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css\" rel=\"stylesheet\">\n    <style>\n        body { padding: 20px; }\n        .container { max-width: 600px; }\n    </style>\n</head>\n<body>\n    <div class=\"container\">\n        <h1>Contact Us</h1>\n        <form method=\"post\">\n            {% csrf_token %} <!-- Required in a real Django app -->\n            {{ form|bootstrap_form }}\n            <button type=\"submit\" class=\"btn btn-primary\">Submit</button>\n        </form>\n\n        <hr>\n        <h2>Individual Field Rendering</h2>\n        <form method=\"post\">\n            {% csrf_token %}\n            {% for field in form %}\n                {{ field|bootstrap_field }}\n            {% endfor %}\n            <button type=\"submit\" class=\"btn btn-success\">Submit Individual</button>\n        </form>\n    </div>\n</body>\n</html>\n'''\n\n# Instantiate the form\nform_instance = MyForm()\n\n# Create a context for rendering\ncontext = Context({'form': form_instance})\n\n# Render the template\ntemplate = Template(template_string)\nrendered_html = template.render(context)\n\n# Print the rendered HTML (in a real Django app, this would be returned by a view)\nprint(rendered_html)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"The `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`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `'django_bootstrap_form'` to your `INSTALLED_APPS` list in `settings.py` and ensure `{% load bootstrap_form %}` is at the top of the template where you use the tags.","cause":"The `django_bootstrap_form` app is not included in your Django project's `INSTALLED_APPS` setting, or the `{% load bootstrap_form %}` tag is missing from your template.","error":"TemplateSyntaxError: 'bootstrap_form' is not a registered tag library"},{"fix":"If you need Bootstrap 4 or 5 styling, either apply custom CSS overrides to the Bootstrap 3 markup generated by this library, write custom form templates using Bootstrap 4/5 classes, or consider using libraries specifically designed for newer Bootstrap versions (e.g., `django-bootstrap4` or `django-bootstrap5`).","cause":"django-bootstrap-form generates HTML markup primarily compatible with Bootstrap 3. Newer Bootstrap versions (4 and 5) have different class names and structural conventions, leading to styling discrepancies.","error":"My Django form, when rendered with django-bootstrap-form, doesn't look like Bootstrap 4 or 5."},{"fix":"Ensure you are passing an instantiated Django `Form` object (e.g., `form_instance`) to `{{ form|bootstrap_form }}` or a `BoundField` (e.g., `form_instance.name`) to `{{ field|bootstrap_field }}`. Always use the form object created in your view, not the class definition.","cause":"You are likely attempting to pass a Django form *field definition* (e.g., `forms.CharField`) directly to a template filter or tag that expects a `BoundField` instance (part of an instantiated form) or an entire form instance.","error":"TypeError: 'CharField' object is not iterable / AttributeError: 'str' object has no attribute 'errors'"}]}