即使用户已登录,用户也永远不会经过身份验证。右侧边栏始终显示 Not Loggedin。我需要返回一些内容到 base.html 吗?我将如何做到这一点?我需要 views.py 中的新功能吗?但是base.hthl 没有url。我错过了什么?请具体说明我在网络开发中。PS:我也尝试过 request.user.is_loggedin 和其他一些
base.html
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/notes/all">Notes</a></li>
</ul>
{% endblock %}
</div>
<div id="rightsidebar">
{% block rightsidebar %}
{% if request.user.is_authenticated %}
Loggedin
{% else %}
Not Loggedin
{% endif %}
{% endblock %}
</div>
<div id="content">
{% block content %}This is the content area{% endblock %}
</div>
视图.py
def auth_view(request):
username = request.POST.get('username','')
password = request.POST.get('password','')
user = auth.authenticate(username = username, password = password)
if user is not None:
if user.is_active:
auth.login(request,user)
return HttpResponseRedirect('/accounts/loggedin')
else:
return HttpResponseRedirect('/accounts/auth_view')
else:
return HttpResponseRedirect('/accounts/invalid')