1👍
✅
When you return a redirect response, you are telling the browser to load a new URL. When the browser requests the new URL, you no longer have access to the old context in the new view.
If you need to pass information to the new URL, you can include it in the URL you redirect to e.g. /rep/22/
or /rep/?id=22
, or by saving data in the session.
However, in this case you don’t need to do that, because you can simply access the logged in user with request.user
.
@login_required
def rep(request):
u = request.user
return render(request, 'retest/home.html', {'u':u})
You don’t even need to include u
in the context. Since you are using the render
shortcut, you should be able to access {{ user }}
in the template, as long as the auth template context processor is enabled.
@login_required
def rep(request):
return render(request, 'retest/home.html', {})
Source:stackexchange.com