Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda