I want to set a cookie inside a view and then have that view render a template. As I understand it, this is the way to set a cookie:
def index(request):
The accepted answer sets the cookie before the template is rendered. This works.
response = HttpResponse() response.set_cookie("cookie_name", "cookie_value") response.write(template.render(context))