0

I pass the context to html and I need to display the values in a for - by key.

is not displayed. how to refer to the value of a dictionary in a loop?

print context

context = {'tag': 'fast', 'view': <orders.views.OrderAddView object at 0x0000000005AB30A0>, 1: <class 'clients.forms.RelatedAddForm'>, 2: <class 'clients.forms.RelatedAddForm2'>, 'count_form': range(1, 3)}

html

 <form action="{% url 'order_add' tag %}" method="post">
        {% csrf_token %}
        {% for x in count_form %}
            {{ x.as_p }} - this does not work
        {% endfor %}
        {{ 1.as_p }} - it works
        <button type="submit" class="btn btn-primary btn-block">Add order</button>
    </form>

that is, how to access the values 1,2, etc. in a loop - 1: <class 'clients.forms.RelatedAddForm'>?

perhaps it is necessary to specify {{context [x] .as_p}} in the loop? how to do it?

JopaBoga
  • 157
  • 11

1 Answers1

1

add all your forms in same list and then iterate forms key from your template :

context.update({'forms' : [Form1, Form2]})
Arzu Huseynov
  • 190
  • 1
  • 8