def func(user):
templatename="login.html"
return render_to_response(templatename,{'user':user},context_instance=RequestContext(request)
What is the scope of the dictionary passed in the render_to_response function in django ? Means could we only use that dictionary in the login.html template or else any template of our app.
The scope of your
dict
is withinlogin.html
only.If you want to use access to the
user
in your template, use something like this:If you want to have a dict with a scope in any template, use context processors
add this in your Settings.py
create a folder in your project root dir, lets name it "utils", inside the folder create init.py file and custom_context_processors.py
custom_context_processors.py
With that,
your_custom_dict
will be available in any template.Note: If you only want to access to the user in any place, just do
{{request.user}}