Open Devinwon opened 6 years ago
简单的示例
{% if username is None %} <div class="item"> <a href="/account/login">登录|注册</a></div> {% else %} <div class="item"> <a href="/account/logout">退出</a></div> {% endif %}
views.py
#POST if userResult and userResult.is_active: response=redirect(to='/') response.set_cookie("username",username,max_age=3600) context["username"]=username return response .... #GET if request.method=="GET": # request.COOKIES["username"] username=request.COOKIES.get("username",None) context["username"]=username return render(request,"login.html",context)
简单的示例
views.py