使用allatuh管理使用者帐号的注册跟登入登出等等
pip安装
pip install django-allauth
到ittest/settings.py设定如下
INSTALLED_APPS = [
# allauth
'django.contrib.auth',
'django.contrib.messages',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.weixin',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Already defined Django-related contexts here
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
]
SITE_ID = 1
SOCIALACCOUNT_PROVIDERS = {
'google': {
# For each OAuth based provider, either add a ``SocialApp``
# (``socialaccount`` app) containing the required client
# credentials, or list them here:
'APP': {
'client_id': '123',
'secret': '456',
'key': ''
}
}
}
到ittest/urls.py修改如下
urlpatterns = [
path('accounts/', include('allauth.urls')),
]
## this to avoid email verification and shows at console
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
浏览器输入
http://127.0.0.1:8000/accounts/email/ or http://127.0.0.1:8000/accounts/signup/
想办法到注册页面
如果跳转到http://127.0.0.1:8000/accounts/profit/ 表示可能已经登入了admin或其他帐号
可以先到/email里面的/signout先登出
注册画面如下
注册完成後验证信的内容会被印在console上面,如下
Subject: [example.com] Please Confirm Your E-mail Address
From: webmaster@localhost
To: [email protected]
Date: Thu, 26 Aug 2021 03:35:29 -0000
Message-ID: <162994892950.22456.17054158323612480632@DESKTOP-CIM6GO4>
Hello from example.com!
You're receiving this e-mail because user test_2 has given your e-mail address to register an account on example.com.
To confirm this is correct, go to http://127.0.0.1:8000/accounts/confirm-email/Mw:1mJ6Ar:_n0VKLEmcg3ryw5OIw1PEgdiPh4aYN-SrM5W_IcUhRY/
Thank you for using example.com!
example.com
<<: 2021-Day6. 铁人赛团体组,Line 群组每日催稿讯息实作教学(二):Send Push Messaging API
>>: Day10 - 读 Concurrency is not Parallelism - Rob Pike (五)
获胜画面 获胜画面我们做一个 modal 好了 如果 游戏状态不是进行中 与 开启modal 的话 ...
每星期及每个月都会有一次固定的会议,加上其他大大小小的会议,一个月至少有6次以上的会议,每次会议看到...
因前篇谈到透过api.kbars抓取1分K的资料内容,但我们在看盘或盘後分析时,可能会用到其它类型的...
图 9-1: 测试建立订单 接续 Day 8 使用 Order API 建立测试订单後,返回结果是...
今天终於没有要讲数字的语法了,要讲的是阵列 那J个是什麽呢,他是方便存放资料的资料型态 今天若是有多...