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 8375581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:12:51+00:00 2026-06-09T15:12:51+00:00

I have a Django forms dilemma. When rendering a form in a template, I

  • 0

I have a Django forms dilemma. When rendering a form in a template, I usually prefer to print the form fields individually, in stead of using the form.as_p annotation. However, in the form I am working on I have a set of fields that are repeated an unknown number of times. For example, if there are 3 items being edited the fields would be:

field_name_1
field_email_1

field_name_2
field_email_2

field_name_3
field_email_3

But the number of items in not known to me beforehand. To solve this I am creating the fields in a loop in the init function, no problems there. But I can’t figure out a way to print the fields individually in the template, since I don’t know the whole name of each field. If this were my only problem I could just use the form.as_p syntax, no biggie. But I would also like to add some html to the beginning of each set of fields, so that the result would be:

Add values 1:
field_name_1
field_email_1

Add values 2:
field_name_2
field_email_2

Add values 3:
field_name_3
field_email_3

However, I haven’t found a way to insert arbitrary html into a form in Django code, similar to #markup in Drupal forms. So:

  1. Is there a way to print the fields individually so I can put the extra html in the template? (What I am missing here is the exact syntax)
  2. If not, how do I insert the extra html into the form?
  • 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-06-09T15:12:53+00:00Added an answer on June 9, 2026 at 3:12 pm

    Do you mean something like this in the template?:

    {% for field in form %}
    <div class="fieldWrapper">
        {{ field.errors }}
        {{ field.label_tag }}: {{ field }}
    </div>
    {% endfor %}
    

    (from the Django documentation: https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs#looping-over-hidden-and-visible-fields )

    You could render the header with something like:
    Add values {{forloop.counter}}:

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

Sidebar

Related Questions

Is it possible to have a variable number of fields using django forms? The
I have a Django my_forms.py like this: class CarSearchForm(forms.Form): # lots of fields like
I have a form like: #forms.py from django import forms class MyForm(forms.Form): title =
I have a form like so: from django import forms from django.contrib.auth.models import User
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I have a Django form that uses a different number of fields based on
I have a Django form using textareas and TinyMCE for text entry. I would
Well, I have one form, similar to dajax django forms example, all is working
I decided to learn Django Forms. For a while now, I have been using
Am using django forms on my app. I have a model Client like this:

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.