Reputation: 133
Are you able to return an array through to a django webpage from the python Views.py file? There may be a way, but I can't figure out how to do it. Now, if I put the array into a dictionary, and return that, I can access the array, which is fine for what I need to do, but I would like to know if there is a way to just return the array and access it on the django template. Thanks:
I can access the following on the template with catarray.0.name.
catarray = [{"name": "Henry", "type": "Tiger", "Awesomeness": "Very"}, {"name": "Bob", "type": "Siamese", "Awesomeness": "Cool"}]
returnobject={'catarray': catarray}
return render(request, "home.html", returnobject)
I cannot access the following and was wondering if it's even possible.
catarray = [{"name": "Henry", "type": "Tiger", "Awesomeness": "Very"}, {"name": "Bob", "type": "Siamese", "Awesomeness": "Cool"}]
return render(request, "home.html", catarray)
Thanks!
Upvotes: 0
Views: 1691
Reputation: 599490
I'm not sure why you would want to do this. The reason that you always pass a dict to render is that each item has a key, which is the name by which you access it in the template. If you passed a list, you wouldn't have a key; how would you reference any of the values?
Upvotes: 3