I have been trying to use the updated yourlabs subscription example, and the installation has worked fine except that
-
Each of the views in the subscription app returns the request variable in the render to template.
-
this
request contextvariable is not received in the template and as a result I am getting the following errorCaught VariableDoesNotExist while rendering: Failed lookup for key [request] in u
Since this is being returned in every view I can’t solve this problem by making some tweaks in a particular template
This is happening because
requestisn’t in your template’s context and the template is using some template code that expected it to be there. That code (e.g. a custom template tag) should better handleVariableDoesNotExistIn addition, your views probably shouldn’t return
requestin every response explicitly. Let Django handle this for you.To do this, add the request template context processor that ships with Django to your
TEMPLATE_CONTEXT_PROCESSORS:If you are already using this template context processor, ensure that
render_to_responseis called withcontext_instance=RequestContext(request)as the final argument (the below example is from the docs):This ensures that all the dicts returned by the template context processors in
TEMPLATE_CONTEXT_PROCESSORSare passed to the template.You could also use the
rendershortcut, which will automatically render the template with an instance ofRequestcontext.Another option added in Django 1.3 is the
TemplateResponse, which will also use an instance ofRequestContext.