第三章 表单与视图.md
最后更新于:2022-04-01 21:59:45
{% trans "Available formats are JPG, GIF, and PNG. Minimal “size is 800 × 800 px." %}
"""), title=_("Image upload"), css_id="image_fieldset", ), layout.Fieldset( _("Contact"), layout.Field("contact_person", css_class="input-blocklevel"), layout.Div( bootstrap.PrependedText("phone", """""", css_class="inputblock-level"), bootstrap.PrependedText("email", "@", css_class="input-block-level", placeholder="contact@example.com"), css_id="contact_info", ), ), bootstrap.FormActions( layout.Submit('submit', _('Save')), ) ) ``` 要渲染模板中的表单,如下,我们只需载入标签冷酷`crispy_forms_tags`,然后使用模板标签`{% crispy %}`: ```python #templates/bulletin_board/change_form.html} {% extends "base.html" %} {% load crispy_forms_tags %} {% block content %} {% crispy form %} {% endblock %} ``` ## 工作原理 拥有新闻简报表的页面的样子大概如此: 图片:略 As you see, the fields are grouped by fieldsets. The first argument of the Fieldset object defines the legend, the other positional arguments define fields. You can also pass named arguments to define HTML attributes for the fieldset; for example, for the second fieldset, we are passing title and css_id to set the HTML attributes title and id. 如你所见,字段是由字段集合组成的。 Fields can also have additional attributes passed by named arguments, for example, for the description field, we are passing css_class and rows to set the HTML attributes class and rows. 字段也可以通过传递命名参数拥有额外的属性,例如, Besides the normal fields, you can pass HTML snippets as this is done with the help block for the image field. You can also have prepended-text fields in the layout, for example, we added a phone icon to the phone field, and an @ sign for the email field. As you see from the example with contact fields, we can easily wrap fields into HTML{% trans "Filter by Genre" %}
{% trans "Filter by Director" %}
{% trans "Filter by Actor" %}
{% trans "Filter by Rating" %}
{{ movie.title }}
{{ movie.title }}
-
{% if object_list.has_previous %}
- « {% else %}
- « {% endif %} {% for page_number in object_list.paginator.page_range %} {% if page_number == object_list.number %}
- {{ page_number }} (current) {% else %}
- {{ page_number }} {% endif %} {% endfor %} {% if object_list.has_next %}
- » {% else %}
- » {% endif %}
Curriculum Vitae
{{ cv.first_name }} {{ cv.last_name }} |
Experience
{{ experience.from_date|date:"F Y" }} -
{% if experience.till_date %}
{{ experience.till_date|date:"F Y" }}
{% else %}
present
{% endif %} |
Skills gained |