How to have a link in label of a form field

Here is the correct link to the Django documentation on the subject of iteration over the form.

What you want is:

<form method="post">
{% for field in form %}
    <p>
        {{ field.errors }}
        {{ field.label_tag }}: {{ field }}
        {% if field.name == "toc" %}
          <a href="{% url terms %}">Terms and Conditions</a>
        {% endif %}
    </p>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
</form>

Import django's mark_safe from utils.safestring as explained at http://www.kelvinism.com/howtos/using-html-django-form-label/

From the link:

from django.utils.safestring import mark_safe
from django import forms

class AccountForm(forms.Form):
    name = forms.CharField(widget=forms.TextInput(), 
                           max_length=15, 
                           label=mark_safe('Your Name (<a href="/questions/whyname/" target="_blank">why</a>?)'))

Tags:

Django