在我的base.html我放了这个:
{% if user.is_authenticated %}
you are logged in!
{% else %}
<h3>Login</h3>
<form action="/login/" method="post" accept-charset="utf-8">
<label for="username">Username</label><input type="text" name="username" value="" id="username" />
<label for="password">Password</label><input type="password" name="password" value="" id="password" />
<p><input type="submit" value="Login →"></p>
</form>
{% endif %}
在urls.py:
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', 'django.contrib.auth.views.logout'),
当我访问时,/login我必须制作一个login.html文件。我创建了templates/registration/login.html:
{% extends "base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username/pass didnt match</p>
{% endif %}
{% endblock %}
我没有看到用户名/密码,但我仍然看到我的用户尚未通过身份验证的含义。
顺便说一句,我没有加载 CSRF 中间件。我错过了一两步吗?
另一件事,我访问logout.html并进入了我的 django 管理员注销页面。我试着做一个templates/registration/logout.html,但它没有覆盖那部分。嗯?