I’m learning django by myself and as you can imagine it’s quite difficult.
I was trying to make a self-adapting form in a view. The app has a model where are stored all the infos about the form (like the placeholder, id and type of the input fields) via JSON (if there’s an easier or smarter way I think it’ll be better).
So, in the views file I’ve passed to the template (picture below) 2 variables which refer to the dict from the object in the picture above.
So, now my scope is to extract the values from the keys "inputType" and "placeholder" in a for statement in the template, in order to insert them into the html file.
With the method above I obviously cannot retrieve anything, but I’m not able to resolve this problem.
This is the view by the way (it is an example, that’s why it has only two fields):
>Solution :
The inputs field seems that contains a dictionary;
in the template you have
{% for campo in inputs %}
but this is valid for lists, maybe you want to use a nested iterators through dictionaries:
{% for key, value in inputs.items %}
{% if key == 'inputs' %}
{% for input_name, input_value in value.items %}
# {{ input_name }} can be nome, cognome, nascita or ammontare
# {{ input_value }} is the value
{% endfor %}
{% endif %}
{% endfor %}
my advice is to organize better the data inside you json field.




