我有两种用户:第一种用户必须付费才能注册到该站点,并且他可以执行一系列操作。在第二个可以注册和登录免费(与他们的Facebook或谷歌或用户名和密码),并可以执行不同的一套动作。
两者都需要有个人资料和自定义字段,当然,用户类型会有所不同。
django django-profiles django-registration django-users django-allauth
我只创建了一个简单的 django 应用程序来使用 tweeter 登录,但是当我尝试从我的应用程序登录时,我收到此消息“您已通过 xxx 身份验证,但无权访问此页面。您想登录到不同的页面吗?”帐户?”

我尝试使用用于创建应用程序的帐户和不同的帐户登录,但结果是相同的。有什么办法可以解决这个问题?
我正在使用 django 和 django-allauth 库
我在 Django 应用程序上使用 AllAuth 来管理用户身份验证。这样我的用户就可以连接他们的 Google 帐户,并且我获得一个 google API 令牌(具有适当的范围)。
我想使用该令牌来访问 google API(在我的例子中是日历 v3),因为我的用户已经使用 OAuth2 登录我的网站,并允许我访问日历 API。
Google 只在他们的网站上提供了完整的流程(从 auth 到 api),有没有办法实现我的想法,或者根本不可能?
我已经尝试过这里drive = build('calendar', 'v3', credentials=credentials)所说的,但“凭据”需要是 oauth2client 的一部分,而不仅仅是一个简单的字符串令牌。
感谢您宝贵的时间。
西蒙
python django google-api google-api-python-client django-allauth
这是我在 Django + React 中的第一个应用程序,所以我并不专业。我正在编写视图集并尝试从请求中获取当前用户,但即使用户已登录,我也得到了匿名用户。我的前端位于 React 中,我正在使用django-allauth和django-rest-auth身份验证。
我试图找出令牌是否存在问题,但似乎效果很好。我也有 CustomUser 所以也许是......
这是我在 React 和 Redux 中的登录功能:
export const authLogin = (username, password) => {
return dispatch => {
dispatch(authStart());
axios.post('http://localhost:8000/rest-auth/login/', {
username: username,
password: password
},)
.then(res => {
const token = res.data.key;
const user = username;
const expirationDate = new Date(new Date().getTime() + 3600 * 1000);
localStorage.setItem('token', token);
localStorage.setItem('user', user);
localStorage.setItem('expirationDate', expirationDate);
dispatch(authSuccess(token));
dispatch(checkAuthTimeout(3600));
})
.catch(err => {
dispatch(authFail(err))
})
}
}
const authSuccess = (state, …Run Code Online (Sandbox Code Playgroud) django django-rest-framework django-allauth reactjs django-rest-auth
美好的一天,我正在尝试覆盖 Django allauth 的 password_reset_email 。问题是它成功覆盖,但我得到的是刚刚发送给用户的 html 代码,而不是 html 表示形式。
我期待收到一封风格化的电子邮件,就像我收到的确认电子邮件一样,但情况似乎并非如此。
在我的templates/registration/password_reset_email.html
{% load i18n %}
{% autoescape off %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Confirm Your E-mail</title>
<style>
.body {
background-color: #f6f6f6;
padding: 30px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.content {
background-color: #FFFFFF;
color: #4d4d4d;
max-width: 400px;
padding: 20px;
margin: auto;
}
.title {
font-size: 20px;
font-weight: 600;
margin: 10px 0;
text-align: center
}
.intro …Run Code Online (Sandbox Code Playgroud) django django-rest-framework django-allauth django-rest-auth
我尝试在我的项目中翻译django-allauth消息。我已经创建了我的翻译文件。但我的翻译默认情况下不用于 django-allath 中存在的任何可翻译句子。看这里:
\n#: templates/account/logout.html:10\nmsgid "Are you sure you want to sign out?" # there are in django-allauth\nmsgstr "\xd9\x85\xd8\xb7\xd9\x85\xd8\xa6\xd9\x86\xdb\x8c \xd9\x85\xdb\x8c\xe2\x80\x8c\xd8\xae\xd9\x88\xd8\xa7\xd9\x87\xdb\x8c \xd8\xae\xd8\xa7\xd8\xb1\xd8\xac \xd8\xb4\xd9\x88\xdb\x8c\xd8\x9f"\n\n#: templates/account/logout.html:20\nmsgid "Cancel" # there aren\'t in django-allauth\nmsgstr "\xd9\x84\xd8\xba\xd9\x88"\nRun Code Online (Sandbox Code Playgroud)\n我在输出中得到这样的东西:
\n您确定要退出吗?-> 输出不是我想要的。django-allauth中有这句话。
\n取消 -> 输出就是我正在寻找的。django-allauth 中没有这句话
\n这是我的setting.py:
#: templates/account/logout.html:10\nmsgid "Are you sure you want to sign out?" # there are in django-allauth\nmsgstr "\xd9\x85\xd8\xb7\xd9\x85\xd8\xa6\xd9\x86\xdb\x8c \xd9\x85\xdb\x8c\xe2\x80\x8c\xd8\xae\xd9\x88\xd8\xa7\xd9\x87\xdb\x8c \xd8\xae\xd8\xa7\xd8\xb1\xd8\xac \xd8\xb4\xd9\x88\xdb\x8c\xd8\x9f"\n\n#: templates/account/logout.html:20\nmsgid "Cancel" # there aren\'t in django-allauth\nmsgstr "\xd9\x84\xd8\xba\xd9\x88"\nRun Code Online (Sandbox Code Playgroud)\n 我想在 django API 中使用 allauth,但是当我安装它时,我遇到了一些错误,我通过 django.setup() 修复了它,之后,我收到错误,告诉我必须设置 DJANGO_SETTINGS_MODULE 现在我在管理中进行了设置。 py:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import django
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
django.setup()
main()
Run Code Online (Sandbox Code Playgroud)
但我得到了这个回溯:
Traceback (most …Run Code Online (Sandbox Code Playgroud) 如何将 Google One Tap 登录体验与 django-allauth 集成?
感谢任何建议。
参考文献:
我正在尝试使用 Django-allauth 进行某些密码重置功能,但是,我正在尝试使用 django-allauth 禁用登录/注册。到目前为止,我还没有找到一种方法将用户重定向到我的自定义注册和登录或完全禁用这些 URL。我想知道是否有解决方法可以删除这些 URL?
我当前的方法是手动添加所有 URL,但不添加这些 URL,但这会导致我的social-login链接出现错误。
目前,我已将以下内容添加到我的网址中:
url(r"^accounts/logout/$", allauth_views.logout, name="account_logout"),
url(r"^accounts/password/change/$", allauth_views.password_change,name="account_change_password"),
url(r"^accounts/password/set/$", allauth_views.password_set, name="account_set_password"),
url(r"^accounts/inactive/$", allauth_views.account_inactive, name="account_inactive"),
# E-mail
url(r"^accounts/email/$", allauth_views.email, name="account_email"),
url(r"^accounts/confirm-email/$", allauth_views.email_verification_sent,name="account_email_verification_sent"),
url(r"^accounts/confirm-email/(?P<key>[-:\w]+)/$", allauth_views.confirm_email,name="account_confirm_email"),
# password reset
url(r"^accounts/password/reset/$", allauth_views.password_reset,name="account_reset_password"),
url(r"^accounts/password/reset/done/$", allauth_views.password_reset_done,name="account_reset_password_done"),
url(r"^accounts/password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",allauth_views.password_reset_from_key,name="account_reset_password_from_key"),
url(r"^accounts/password/reset/key/done/$", allauth_views.password_reset_from_key_done,name="account_reset_password_from_key_done"),
# social account
path('socialaccount/login/cancelled/', allauth_socialviews.login_cancelled,name='socialaccount_login_cancelled'),
path('socialaccount/login/error/', allauth_socialviews.login_error,name='socialaccount_login_error'),
path('socialaccount/signup/', allauth_socialviews.signup, name='socialaccount_signup'),
path('socialaccount/connections/', allauth_socialviews.connections, name='socialaccount_connections'),
Run Code Online (Sandbox Code Playgroud)
但是,由于我有 Google 社交登录,因此出现错误:
Reverse for 'google_login' not found. 'google_login' is not a valid view function or pattern name
我怎样才能实现这个而不引起任何错误?
我在使用 dj_rest_auth jwt 包时遇到问题。当我注册一个新帐户时,它会为我提供访问令牌和刷新令牌作为响应,但是当我尝试使用凭据登录时,我得到的只是访问令牌,而刷新令牌完全是空的!我按照文档和我遵循的教程中的描述配置了代码。对这个问题有什么想法吗?请告诉我。
更新:我刚刚发现刷新令牌已在响应标头中正确设置,但我无法弄清楚为什么它不在响应正文中并且显示为空?!
设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'rest_framework.authtoken',
'allauth',
'allauth.account',
'allauth.socialaccount',
'dj_rest_auth',
'dj_rest_auth.registration',
'accounts.apps.AccountsConfig',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'accounts.permissions.IsStaffOrReadOnly',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
],
}
SITE_ID = 1
REST_AUTH = {
'USE_JWT': True,
'JWT_AUTH_COOKIE': 'access',
'JWT_AUTH_REFRESH_COOKIE': 'refresh',
}
Run Code Online (Sandbox Code Playgroud)
回复:
{
"access_token": "eyJhbGciOiJ.....",
"refresh_token": "",
"user": {
"pk": 2,
"username": "test_user_0",
"email": "test0@mysite.co",
"first_name": "",
"last_name": ""
}
}
Run Code Online (Sandbox Code Playgroud) django jwt django-rest-framework django-allauth dj-rest-auth
django-allauth ×10
django ×9
dj-rest-auth ×1
django-urls ×1
django-users ×1
django-views ×1
google-api ×1
jwt ×1
oauth ×1
python ×1
reactjs ×1