{{ form.as_ul }} Render Django Forms as list (original) (raw)

Last Updated : 11 Jun, 2026

The {{ form.as_ul }} method renders Django form fields as HTML list items. Each form field is wrapped inside an

  • element, making it suitable for forms that need to be displayed as an unordered list. This approach allows forms to be rendered with minimal template code while maintaining a structured layout.
  • **Example:

    {% csrf\_token %}

    Using {{ form.as_ul }} to Render Django Forms

    **Example: Create a project named geeksforgeeks having an app named geeks and create a sample Django Form to render it.

    In **geeks /forms.py,

    Python `

    from django import forms

    creating a form

    class InputForm(forms.Form):

    first_name = forms.CharField(max_length = 200)
    last_name = forms.CharField(max_length = 200)
    roll_number = forms.IntegerField(
                     help_text = "Enter 6 digit roll number"
                     )
    password = forms.CharField(widget = forms.PasswordInput())

    `

    In **views.py,

    Python `

    from django.shortcuts import render from .forms import InputForm

    Create your views here.

    def home_view(request): context ={} context['form']= InputForm() return render(request, "home.html", context)

    `

    In **templates /home.html,

    html `

    {% csrf_token %}

    `

    Open http://localhost:8000/ python-django-form-as-ul Let's check the source code whether the form is rendered as a list or not. By rendering as a list it is meant that all input fields will be enclosed in

  • tags. Here is the demonstration,
  • **Explanation:

    **Note: {{ form.as_ul }} only affects how form fields are rendered in HTML. It does not change form validation, submission handling, or database operations.

    Other Methods

    )
    Method Output
    {{ form.as_ul }} Renders fields inside
  • tags
  • {{ form.as_p }} Renders fields inside

    tags

    {{ form.as_table }} Renders fields inside table rows (

    When to Use form.as_ul

    How to Create a Basic Project using MVT in Django? How to Create an App in Django ? {{ form.as_table }} {{ form.as_p }}