首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dj-rest-auth注册获取

dj-rest-auth注册获取
EN

Stack Overflow用户
提问于 2022-07-16 10:48:08
回答 1查看 93关注 0票数 1

使用dj auth作为用户auth和注册在我的反应应用程序。获得登录和注销,使用文档中的api端点工作。未能注册用户,收到HTTP错误请求400。在网上阅读,解释说我的要求有问题,但不知道是什么。

编辑:尝试模拟注册后的响应,并在Django的侧得到错误:

代码语言:javascript
复制
ConnectionRefusedError at /api/dj-rest-auth/registration/
[Errno 61] Connection refused

register.js

代码语言:javascript
复制
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

代码语言:javascript
复制
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...
]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-04 12:08:11

这个问题出现在drf auth的配置设置中,在这种情况下,它将处理:

代码语言:javascript
复制
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_AUTHENTICATION_METHOD = 'username'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73003541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档