1👍
✅
This doesn’t have anything to do with the login_required
decorator or jinja2, the problem is in your view. You should use the render
shortcut instead of render_to_response
.
from django.shortcuts import render
@login_required()
def displaystats(request):
...
return render(request, 'displaystats.html', {'listpackages': listpackages})
When you use render_to_response
you have to explicitly use a RequestContext
so that the auth context processor runs and includes user
in the template context. The render
shortcut does it automatically.
Source:stackexchange.com