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>
<p>{% trans "Form submitted successfully" %}</p>
{% if data %}<p>{% blocktrans with link=data.show_url_link %}For your convenience you can see your data at {{ link }}.{% endblocktrans %}</p>{% endif %}
The DynamicTemplateView exposes two variables to the template context related to the form:
- model
- An instance of the form model assigned to this URL.
- data
- If an instance of FormModelData if a existing display_key is given and the form model (model) has set allow_display to True.
Third Party Apps¶
django-simple-captcha¶
django-simple-captcha provides easy CAPTCHA support for Django forms. This contrib package integrates django-simple-captcha into django-dynamic-forms allowing users to add a CAPTCHA field to their dynamic forms.
To use it make sure you installed django-simple-captcha:
$ pip install django-simple-captcha
Next put 'captcha' and 'dynamic_forms.contrib.simple_captcha' in the INSTALLED_APPS:
INSTALLED_APPS = (
...
'captcha',
'dynamic_forms.contrib.simple_captcha',
...
)