description: django-allauth
用户系统
使用django-allauth(0.39.1)
安装
pip install django-allauth配置
settings.py (Important - Please note ‘django.contrib.sites’ is required as INSTALLED_APPS):```python
Specify the context processors as follows:
TEMPLATES = [ { ‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’, ‘DIRS’: [], ‘APP_DIRS’: True, ‘OPTIONS’: { ‘context_processors’: [
1
2
3
4
5
6# Already defined Django-related contexts here
# `allauth` needs this from django
'django.template.context_processors.request',
],
},}, ]
AUTHENTICATION_BACKENDS = ( …
1 | # Needed to login by username in Django admin, regardless of `allauth` |
)
INSTALLED_APPS = ( …
1 | # The following apps are required: |
)
SITE_ID = 1
############
allauth基本设定 #
############
ACCOUNT_AUTHENTICATION_METHOD = ‘username_email’ ACCOUNT_EMAIL_REQUIRED = True LOGIN_REDIRECT_URL = “/case”
ACCOUNT_SIGNUP_FORM_CLASS = ‘users.forms.registions’
AUTHENTICATION_BACKENDS = ( ‘allauth.account.auth_backends.AuthenticationBackend’, ‘django.contrib.auth.backends.ModelBackend’, )
####################
django-auth登录地址设定 #
####################
LOGIN_URL=”/users/login/“ #?next=/
######
邮箱设定 #
######
EMAIL_HOST = “smtp.mail.com” EMAIL_PORT = 25 #QQ邮箱使用587 EMAIL_HOST_USER = “user@mail.com“ EMAIL_HOST_PASSWORD = “password” # 这个不是邮箱密码,而是授权码 EMAIL_USE_TLS = True # 这里必须是 True,否则发送不成功 EMAIL_FROM = “user@mail.com“ # 发件人 DEFAULT_FROM_EMAIL = “UNOECP user@mail.com“ # 默认发件人(如果不添加DEFAULT_FROM_EMAIL字段可能会导致如下错误: 451, b’Sender address format error.’, ‘webmaster@localhost’)
1 | urls.py: |
数据库
python manage.py migrateallath没有用户资料修改功能,需要自己编写,可以扩展用户资料,相关问题想看代码本部分,在url中的配置参考以下
1
2url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/profile/', include('users.urls')),
****
本文作者:Samjoe Yang
本文链接: https://need.uno/django-course-yong-hu-xi-tong/
版权声明:本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论