简体   繁体   中英

How does the {{ form }} tag work in Django-registration app

I downloaded and installed django-registration app. I also downloaded a template that has this strange piece of code

{{ form }}

that magically creates 4 labels and 4 textboxes for the user to enter his registration information. How does it work?

{% extends "registration/registration_base.html" %}
{% block title %}Register for an account{% endblock %}
{% block content %}

<table>
    <form method='post' action=''>{% csrf_token %}
        {{ form }}
        <tr><td></td><td><input type="submit" value="Send activation email" /></td>
    </form>
</table>
{% endblock %}

It is part of django forms. See the documentation for more info.

https://docs.djangoproject.com/en/1.3/topics/forms/

If you are really interested check out the source code.

https://code.djangoproject.com/browser/django/trunk/django/forms

A django form (but other objects, too) has a unicode method, which is invoked, when a string representation of the object is requested. As you can see in the code, it just passes the call on to as_table - which in turn uses a generic helper function: _html_output . This basically loops over all the fields and constructs the HTML which then is returned and displayed on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM