Problem is that i can’t get value to my template.
Views.py:
from django.shortcuts import get_object_or_404, render_to_response
from django.httpimport HttpResponse
def index(request):
c='hi'
return render_to_response('list.html', c)
list.html:
{% extends "base.html" %}
{% block content %}
list{{ c }}
{% endblock %}
It renders list but not{{ c }} what could cause this? And it gives no error..
render_to_responseexpects its context to be a dictionary, whereas you are passing your string directly:Based on your comment below, if you want ‘c’ to be a list of things, it would look something like this instead:
The basic idea is that you’re building a mapping of the variables you want to reference in your template. The names that you reference in the template are keys in the dictionary.