Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Django form fields to HTML

I'm crating fields in a for loop and storing them in a list in a Django form. When trying to place the fields in the HTML file, it appears to be printing the object.

Something like this: <django.forms.fields.IntegerField object at ...>

My HTML looks like this:

{% for i in form.list %}
    {{i}}
{% endfor %}

This is how I create the list:

l1 = [] #List that contains names 
l2 = [] #List that contains other names 
result = {} 
for i in l1: 
   for j in l2: 
      v_name = i + '_' + j 
          result[v_name] = forms.IntegerField()

How can I convert that string to an actual input?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can add fields to the self.fields dictionary in Form.__init__ to dynamically add fields to a form.

class MyForm(forms.Form):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for i in l1: 
            for j in l2: 
                v_name = i + '_' + j 
                self.fields[v_name] = forms.IntegerField()

This can be used like a regular form, or iterated over

{{ form }}

{% for field in form %}
    {{ field }}
{% endfor %}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!