Reputation: 8580
I am having trouble with what seems to be a simple problem:
I want to pass a dictionary to a template, and then have the template render that dictionary on the page. However, when I run the page, the dictionary doesn't show up...
Here's my views page:
def display_meta(request):
values = request.META.items()
values.sort()
c = Context(values)
return render_to_response('meta_data.html', c)
And here's my template:
{% extends "base.html" %}
{% block content %}
<table>
{% for k, v in c %}
<tr><td> {{k}} </td><td> {{v}} </td></tr>
{% endfor %}
</table>
{% endblock %}
I am not sure what is going wrong. Any help would be greatly appreciated. Thanks!
Upvotes: 0
Views: 369
Reputation: 11259
You need to pass context as a dict. You would do so like
def display_meta(request):
values = request.META.items()
values.sort()
return render_to_response('meta_data.html', {'c': values})
Each key represents the variable that will be available, in this case c
will be a dict with the items in values
Upvotes: 1