4π
{% 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" />
</form>
by the sample code in your question.
Now Parameter "form" contains a valid Django Form
Hope this helps
3π
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
- What's equivalent to Django's auto_now, auto_now_add in SQLAlchemy?
- What is the opposite of @login_required decorator for Django views?
- Error: command 'x86_64-linux-gnu-gcc' when installing mysqlclient
- Django 1.9 JSONField order_by
- TypeError: __call__() missing 1 required positional argument: 'send' Django
1π
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" />
</form>
- Inline-like solution for Django Admin where Admin contains ForeignKey to other model
- Found another file with the destination path β where is that other file?
- Django Rest Framework reverse and SimpleRouter
- System date formatting not using django locale
- Django form dropdown list of stored models
0π
You donβt really need the bootstrap_button tags. I tried to find them as well, but they are not declared in the sourceβ¦
0π
Put {% extends 'bootstrap3/bootstrap3.html' %}
at the beginning of your snippet. Itβs supposed to be your file, bootstrap3.html is at this placeholder.
- Django + Forms: Dynamic choices for ChoiceField
- Django multi-table inheritance alternatives for basic data model pattern
- Using Django Login Required Mixin
- Django KeyError: "'__name__' not in globals"
- Django reset_password_confirm TemplateSyntaxError problem
0π
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.
- Creating django forms
- Django logging β django.request logger and extra context
- Django redirect() with anchor (#) parameters
-1π
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:
https://docs.djangoproject.com/en/1.8/topics/forms/#the-template
{% load bootstrap3 %}
{# Display a form #}
<form action="/submit/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
- Django-allauth SITE_ID error
- How to have a "random" order on a set of objects with paging in Django?
- ImportError: cannot import name generic
- One-Time User Authentication with SMS Using Django and Twilio
- How to read sql query to pandas dataframe / python / django