首页 > 代码库 > DJANGO用户名认证一例

DJANGO用户名认证一例

现在实例了用户登陆,就自带的功能。。

urls.py

~~~~~~~~~~

(r‘^login/$‘, login),
(r‘^logout/$‘,logout,{‘next_page‘:‘/login/‘}),

~~~~~~~~~~~~

views.py

~~~~~~~~~~~~

if request.user.is_authenticated():
username = request.user.username

~~~~~~~~~~~~~~~~~~~

login.html

~

{% block content %}

{% if form.errors %}
<p class="error">Sorry, that‘s not a valid username or password</p>
{% endif %}

<form action="" method="post">
{% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">

<input type="submit" value="http://www.mamicode.com/login" />
<input type="hidden" name="next" value="http://www.mamicode.com/saltstack/" />
</form>

{% endblock %}

DJANGO用户名认证一例