使用dj auth作为用户auth和注册在我的反应应用程序。获得登录和注销,使用文档中的api端点工作。未能注册用户,收到HTTP错误请求400。在网上阅读,解释说我的要求有问题,但不知道是什么。
编辑:尝试模拟注册后的响应,并在Django的侧得到错误:
ConnectionRefusedError at /api/dj-rest-auth/registration/
[Errno 61] Connection refusedregister.js
fetch('/api/dj-rest-auth/registration/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
user: 'alalala',
password1: '1234',
password2: '1234',
email: 'ala@gmail.com',
})
})
.then(res => {
res.json()
})settings.py
SITE_ID = 1
CORS_ORIGIN_ALLOW_ALL = True
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
]
}
REST_AUTH_REGISTER_SERIALIZERS = {
'REGISTER_SERIALIZER': 'api.serializers.CustomRegisterSerializer'
}
INSTALLED_APPS = [
#local
'api',
# 3'rd party apps
'rest_framework',
'corsheaders',
'rest_framework.authtoken',
'dj_rest_auth',
'allauth',
'allauth.account',
'allauth.socialaccount',
'dj_rest_auth.registration',
# added django but it disable admin login logout pages
'django.contrib.sites',
# django default...
]发布于 2022-09-04 12:08:11
这个问题出现在drf auth的配置设置中,在这种情况下,它将处理:
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_AUTHENTICATION_METHOD = 'username'https://stackoverflow.com/questions/73003541
复制相似问题