【发布时间】:2021-08-18 21:47:13
【问题描述】:
我在尝试从我的前端移动应用发布到我的 Django 服务器时收到 403 错误。但是,当我在浏览器上使用表单发布时,它完全可以正常工作。
我曾经使用我的前端移动应用注册过一次,但从那以后,我收到了这个 403 错误。我已经尝试过注册和登录。
这是我在 Django 后端终端中遇到的错误:
Bad Request: /rest-auth/registration/
[16/Aug/2021 14:51:37] "POST /rest-auth/registration/ HTTP/1.1" 403 58
这是我的 settings.py 文件:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'users',
]
SITE_ID = 1
....
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
ACCOUNT_EMAIL_VERIFICATION = 'none'
这是我的前端(register.js):
axios
.post("http://127.0.0.1:8002/rest-auth/registration/", {
username: "tester1234@gmail.com",
email: "tester1234@gmail.com",
password1: "tester1234@gmail.com",
password2: "tester1234@gmail.com",
})
我做错了什么?我只希望用户能够注册、登录和退出我的应用。
【问题讨论】:
-
您是否记得将身份验证路径添加到您的 urls.py 中?
标签: django authentication django-rest-framework axios django-rest-auth