我正在研究 Django 项目,我搜索了一段时间如何登录并发现最简单的方法是“django.contrib.auth”。所以我将我的登录视图添加到 urls.py :
url(r'^login/$','django.contrib.auth.views.login',{'template_name': 'login.html'}),
这是我的模板:
<html>
<head>
<title>Django Bookmarks - User Login</title>
</head>
<h1>User Login</h1>
{% if form.errors %}
<p>Your username and password didn't match.
Please try again.</p>
{% endif %}
<form method="post" action=".">{% csrf_token %}
<p><label for="id_username">Username:</label>
{{ form.username }}</p>
<p><label for="id_password">Password:</label>
{{ form.password }}</p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
</body>
</html>