Usage

Using Custom Templates

django-dynamic-forms comes with a basic template that just displays the form or a success page. You can customize these templates to your needs.

The Form Template

The following code shows the default template rendering a dynamic form.

{% load i18n %}
<h2>{{ name }}</h2>
<form method="post" action="{{ submit_url }}">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">{% trans "Submit" %}</button>
</form>

The DynamicFormView exposes three variables to the template context related to the form:

form
An instance of the form that will be shown on this page. As the form is a normal Django form, all rules from the Django documentation apply.
model
An instance of the form model providing the form and assigned to this URL.
name
The form’s name as defined in dynamic_forms.models.FormModel.name.
success_url
The URL the form will be submitted to as defined in dynamic_forms.models.FormModel.submit_url. This is not the success_url!

The Success Template

The following code shows the success template after a successful form submit.

{% load i18n %}
<h2>{% trans "Success" %}</h2>
<div>{% trans "Form submitted successfully" %}</div>

The DynamicTemplateView exposes three variables to the template context related to the form:

model
An instance of the form model assigned to this URL.

Table Of Contents

Previous topic

Installation

Next topic

Problems

This Page