django使用登录模板登录如果login页面不加<input type="hidden" name="next" value= {{next}} />
默认登录后跳转到/accounts/profile/
如果指定登陆后跳转的页面进行如下设置
登陆后指定跳转到|/lib/detail/
页面
login.html页面:
{% if form.errors %}
<p>Your username and password didn`t math.Please try again.</p>
{%endif%}
<form method="POST" action="{% url 'lib:login'%}">
{%csrf_token %}
{{form.as_p}}
<button name= 'submit'>log in</button>
<input type="hidden" name="next" value="{% url 'lib:detail' %}"/>
</form>
如果登录后返回登陆前页面可以写:
login.html:
{% if form.errors %}
<p>Your username and password didn`t math.Please try again.</p>
{%endif%}
<form method="POST" action="{% url 'lib:login'%}">
{%csrf_token %}
{{form.as_p}}
<button name= 'submit'>log in</button>
<input type="hidden" name="next" value= {{next}} />
</form>
这样如果访问需要登录的页面http://127.0.0.1:8000/lib/detail/
时,将会跳转到登录页面;
地址栏地址是http://127.0.0.1:8000/login/?next=/lib/detail/
那么登录后就会自动返回到http://127.0.0.1:8000/lib/detail/
返回登陆前的页面。