This article mainly introduces how to use CSS in Django form design. Django is the most famous Python popular development framework, the quickest way to modify the display of a form is to use CSS. Especially the Error List, which can enhance the visual effect. The automatically generated Error List accurately uses''
'', So that we can use CSS for them. The following CSS makes the error more eye-catching:
Although it is convenient to automatically generate HTML, you may want to overwrite the default display in some cases. {Form. as_table} and other methods are quick methods during development. form display methods can also be easily rewritten in form.
Each field component (,,Or similar), you can access {form. Field name} for separate rendering. </P>
Contact us Contact us {% if form.errors %} Please correct the error{{ form.errors|pluralize }} below.
{% endif %}
{Form. message. errors} Will
If the field is valid or the form is not bound, an empty string is displayed. We can also treat form. message. errors as a Boolean value or perform iteration on the list. For example:
{% if form.message.errors %}
{% for error in form.message.errors %}
- {{ error }}
{% endfor %}
{% endif %} Message: {{ form.message }}
If the verification fails, this Code adds an "errors" to the class attribute of p containing the error field and displays the error information in an ordered list.