1π
user
is automatically provided to the template via the context processor. But these only run if you are using a RequestContext
when rendering your template: either by specifically passing it in (eg with the context_instance
parameter to render_to_response
), or by using the newer render
shortcut.
So in all your other views, you need to be sure you are doing:
return render(request, 'your_template.html', params)
0π
Looks like the user object is not available inside your template. If the user object is not available in the template, nothing will be displayed when the template evaluates {{ user.username }}
From the docs β
If you use a variable that doesnβt exist, the template system will
insert the value of the TEMPLATE_STRING_IF_INVALID setting, which is
set to β (the empty string) by default.
You can pass the user object to the template by modifying the appropriate view which returns the welcome template, using either render()
which forces the use of a RequestContext
implicitly or render_to_response()
where you have to explicitly pass a RequestContext
instance
- [Answer]-Django: How to add errors messages next to the form
- [Answer]-Save form fields as a draft DJANGO
- [Answer]-How to upload data in model through migrations in django?
- [Answer]-Required and Optional Field in Django Formset
- [Answer]-Django; Why empty_label is not shown in ModelChoiceField?
0π
in your views.py you should use RequestContext
from django.template import RequestContext
from django.shortcuts import render_to_response
def login(request):
args={}
...
return render_to_response('login.html', args, context_instance=RequestContext(request))