![]() |
VOOZH | about |
The {{ form.as_p }} method renders Django form fields as HTML paragraphs. Each form field, along with its label and validation errors, is wrapped inside a <p> element. This provides a quick way to display forms with minimal template code while maintaining a clean vertical layout.
Example:
<form method="post">
{% csrf_token %}
{{ form.as_p }}
</form>
Example: Create a project named geeksforgeeks having an app named geeks and create a sample Django Form to render it.
In geeks /forms.py,
In views.py,
In templates /home.html,
Open http://localhost:8000/: 👁 Image
Check the source code whether the form is rendered as a paragraph or not. By rendering as a paragraph it is meant that all input fields will be enclosed in <p> tags. Here is the demonstration.👁 Image
Explanation:
Note: {{ form.as_p }} controls only the HTML layout of the form fields. It does not affect form validation, submission handling, or database operations.
| Method | Output |
|---|---|
| {{ form.as_p }} | Renders fields inside <p> tags |
| {{ form.as_table }} | Renders fields inside table rows (<tr>) |
| {{ form.as_ul }} | Renders fields inside list items (<li>) |
How to Create a Basic Project using MVT in Django?
How to Create an App in Django ?
{{ form.as_table }}
{{ form.as_ul }}