I am new to python and django and was wondering how I would go about making a dict of lists.
My 4 lists are;
ap = request.POST.getlist('amount_paid[]')
pd = request.POST.getlist('paid_date[]')
method = request.POST.getlist('method[]')
comments = request.POST.getlist('comments[]')
How would I make that into a dictionary I could then loop over in a django template such as;
{% for i in the_dict %}
{{i.amount_paid}}
{% endfor %}
Thanks in advance!
Update:
hmm I not sure I posted my question properly. In php, I can do the following on an array of fields:
for($i=0;$i<count($_POST['amount_paid']);$i++) {
echo $_POST['amount_paid'][$i];
echo $_POST['paid_date'][$i];
}
All the form fields are input text fields.. How would I do this in Django?
Python’s
dictsyntax is very simple. It’s just key-value pairs inside a pair of curly braces, like this:Following your update, it looks like you don’t want a
dictat all butzip():