博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用User authentication and permissions
阅读量:7195 次
发布时间:2019-06-29

本文共 1937 字,大约阅读时间需要 6 分钟。

这篇文章是笔记,详细内容参见Mozilla的教程

完整的教材:

1, 确认settings.py的INSTALLED_APPS和MIDDLEWARE里面包含下面红色的组件:

INSTALLED_APPS = [    ...    'django.contrib.auth',      'django.contrib.contenttypes',    ....MIDDLEWARE = [    ...    'django.contrib.sessions.middleware.SessionMiddleware',    ...    'django.contrib.auth.middleware.AuthenticationMiddleware',      ....

2, 使用admin页面创建user、group。

3, 在主项目的urls.py文件内添加下面的内容:

urlpatterns += [    url('^accounts/', include('django.contrib.auth.urls')),]

4, 上面url将为我们自动创建下列的url即相对应的form、views。

^accounts/ ^login/$ [name='login']^accounts/ ^logout/$ [name='logout']^accounts/ ^password_change/$ [name='password_change']^accounts/ ^password_change/done/$ [name='password_change_done']^accounts/ ^password_reset/$ [name='password_reset']^accounts/ ^password_reset/done/$ [name='password_reset_done']^accounts/ ^reset/(?P
[0-9A-Za-z_\-]+)/(?P
[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$ [name='password_reset_confirm']^accounts/ ^reset/done/$ [name='password_reset_complete']

5, 在app文件夹内的templates目录下面创建registration目录,并在settings.py 文件夹内添加:

TEMPLATES = [    {        ...        'DIRS': ['./templates',],        'APP_DIRS': True,        ...

6, 由此我们可以在registration目录下面创建下面的templates:

login.html – 当用户登陆网站时展示的页面
logged_out.html – 当用户登出网站后展示的页面
password_change_done.html – 当用户成功更改其账户密码后展示的页面
password_change_form.html – 用于处理用户更改其账户密码时展示的页面
password_reset_complete.html – 当用户成功重置其账户密码后展示的页面
password_reset_confirm.html – 用于处理用户输入其新账户密码时的页面
password_reset_done.html – 用于提示账户,重置密码连接已经发送到他或她的邮箱时的页面
password_reset_email.html – 邮件模板,内含重置账户密码链接
password_reset_form.html – 用于提示用户输入注册时用的邮箱地址以获得重置账户密码的链接
而如果要用URL tag指向这些templates,需要参考第四点中所列出的url。如指向password_reset_form.html可以使用下面的方式:

忘记密码?

7, 上面的这些templates都要我们自己编写。下面是编写password_reset_email.html时要添加的内容,其他templates不举例:

{
{ user.get_username }}, 你好!你可以点击如下链接以重置你的密码:{
{ protocol }}://{
{ domain }}{% url "password_reset_confirm" uidb64=uid token=token %}

转载地址:http://akxkm.baihongyu.com/

你可能感兴趣的文章
javaweb入门(4)-- 详细了解http协议2
查看>>
POJ-3686 The Windy's 犀利构图+KM
查看>>
重新认识c++的cin、cout
查看>>
poj1611
查看>>
多例设计模式与枚举
查看>>
【转】Scrum角色及其职责介绍
查看>>
【动画】【特效】activity跳转华丽的过渡效果(转载)
查看>>
使用Eclipse进行远程调试【转】
查看>>
闲谈简单设计(KISS)疑惑
查看>>
四、Html5 语音识别
查看>>
<![CDATA[ ]]> 是什么东东
查看>>
Logger 源码解析 --- MyLogger
查看>>
设置VMware随系统开机自动启动并引导虚拟机操作系统
查看>>
元对象我所理解的设计模式(C++实现)——享元模式(Flyweight Pattern)
查看>>
iOS5新开发的API总述
查看>>
20130605
查看>>
zoj 3278 8G Island
查看>>
由于物化视图定义为on commit导致update更新基表慢的解决方案
查看>>
常见的网络名词解释
查看>>
Commons IO方便读写文件的工具类
查看>>