Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4347264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:16:58+00:00 2026-05-21T12:16:58+00:00

I want to parse the fields of my Modelform separately and not in a

  • 0

I want to parse the fields of my Modelform separately and not in a for loop. And i want some fields to parse the Django HTML for that element.
I have this:

<form action="#" method="POST" name="notifictaionForm">
    <ul>  
        <li><label>{{ form.fields.title.label }}</label> <span>{{ notification.title }}</span></li>
        <li><label>{{ form.fields.create_date.label }}</label> <span>{{ notification.create_date }}</span></li>
        <li><label>{{ form.fields.description.label }}</label> <span>{{ notification.description }}</span></li>
        <li><label>{{ form.fields.status.label }}</label> <span>{{ form.fields.status.??? }}</span></li>
    </ul>
</form>

So i can parse the name of the field but not the HTML element, i want at the ??? in the template code to parse the Django HTML form element.

Does somebody know how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:16:58+00:00Added an answer on May 21, 2026 at 12:16 pm

    If I’ve understood you well, You want django’s auto-generated html for status field? Then it is very simple:

    {{ form.status }}
    

    Few extra words:

    Form is dict-like object where fields can be accessed like this:

    >>> form['field_name']
    

    Declared fields are stored in form.fields, a SortedDict object. So you can use this variable to access fields, however recommended way is always the shortest way.

    If you are new to Python, you might wonder how is it so that you declare fields as attributes, however you are not able to access them from python code like this:

    >>> form.field_name
    AttributeError: 'Form' object has no attribute 'field_name'
    

    Well it is because classes in python aren’t static, the meta-class can be used to build all kind of new things out of class definition. Django makes use of it to create a friendly API. Basically it goes like this:

    1. Python interpreter parses your Form class.
    2. Interpreter finds __metaclass__ attribute which is inherited from django.forms.Form and is set to: DeclarativeFieldsMetaclass.
    3. Metaclass restructures your class. Attributes are removed and .base_fields attribute is created.
    4. Why base_fields not fields? Well it is another story, this has do with how fields which comes from models in ModelForm are separated from fields declared in form class.

    But do not confuse metaclasses with the class Meta which is sometimes used to provide additional configuration options to your form or model.

    Back to templates now. You can not access form.field_name from python code, why then it is possible in template? As described in django documentation, when the template system encounters a dot, it tries the following lookups, in this order:

    • Dictionary lookup
    • Attribute lookup
    • Method call
    • List-index lookup

    That means first thing template system will try to return when it encounters: {{ form.field_name }} is: form['field_name'].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a page,say abc.html, that is having a small form with some fields.
I want to parse this CSS Selector (and others of a similar form): div.class1#myid.class2[key=value]
I use GLib to parse some command-line options. The problem is that I want
I have some JSON I'm trying to parse. I don't know if this is
I want to parse xml file in utf-8 and sort it by some field.
I want to parse something like this: Hi [{tagname:content}] [{tag1:xnkudfdhkfujhkdjki diidfo now nested tag
I want to parse a xml file using xquery in Ruby, I found this
I want to parse a SQL query into an array. I could not figure
I have a stack of CSV files I want to parse - the problem
In short, this is a sketch of the JSON object I want to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.