Reputation: 3308
If I make a context processor like this:
def add_external(request):
context = {"stext":"this is the info"}
return context
and add this to the settings:
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'website.context_processor.add_external',
],
I can access the variable in the template via {{stext}}
. When I now jump from a link in this template into another view in the same app shouldn't I be able to access this variable as:
request.stext
Instead I get this error:
'WSGIRequest' object has no attribute 'stext'
What I am missing here?
Upvotes: 3
Views: 6060
Reputation: 670
You implemented context processor, which data are available only inside of templates, but not the request
object.
You may want to use custom request middleware.
Upvotes: 2