简体   繁体   English

{{ form }} 标签如何在 Django-registration 应用程序中工作

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

I downloaded and installed django-registration app.我下载并安装了 django-registration 应用程序。 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.它神奇地创建了 4 个标签和 4 个文本框,供用户输入他的注册信息。 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.它是 django forms 的一部分。 See the documentation for more info.有关更多信息,请参阅文档。

https://docs.djangoproject.com/en/1.3/topics/forms/ 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 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. django 表单(但也包括其他对象)具有unicode方法,当请求 object 的字符串表示时,将调用该方法。 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 .正如您在代码中看到的那样,它只是将调用传递给as_table - 而后者又使用通用帮助程序 function: _html_output This basically loops over all the fields and constructs the HTML which then is returned and displayed on the page.这基本上循环所有字段并构造 HTML 然后返回并显示在页面上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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