[Fixed]-Error loading sample django-bootstrap3 template


{% bootstrap_form form %} is a template tag provided by django-bootstrap3 that expect a django form instance, so the “form” parameter is the context variable mentioned in displaying-a-form-using-a-template from django docs.

Create the form as explained in that page, and then replace the html code they use in template:

<form action="/contact/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />

by the sample code in your question.

Now Parameter "form" contains a valid Django Form

Hope this helps


You just need to provide an object form server side, which must have a context name “form”.

In your views.py, include something like this

from django.shortcuts import render

def index(request):
    from django import forms
    class NameForm(forms.Form):
        your_name = forms.CharField(label='Your name', max_length=100)

    template = "your_template.html"
    context = { "form" : NameForm() }
    return render( request, template, context )

Now you should not have any error.

Hope it helps



try this

{# Load the tag library #}
{% 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/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="btn btn-primary" value="Submit" />


You don’t really need the bootstrap_button tags. I tried to find them as well, but they are not declared in the source…



Put {% extends 'bootstrap3/bootstrap3.html' %} at the beginning of your snippet. It’s supposed to be your file, bootstrap3.html is at this placeholder.


Error is pretty straightforward, make sure you pass valid django form. I was passing form.as_p() instead of form in my view and got this error. Took me a while to notice. May be it will still help somebody.


for django 1.8 use {{ form }} instead of {{ form.as_p }} as in django 1.6, for this minor change can cause an error

please see django 1.8 official documentation:

{% load bootstrap3 %}
{# Display a form #}

<form action="/submit/" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />

Leave a comment