首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到django-rest-auth urls

找不到django-rest-auth urls
EN

Stack Overflow用户
提问于 2020-06-21 13:37:44
回答 3查看 875关注 0票数 0

我正在尝试实现django-rest-auth,但是url无法识别并抛出404错误。'rest_auth‘被添加到INSTALLED_APPS中,路径也包含在urls.py文件中。

代码语言:javascript
复制
Request URL:    http://127.0.0.1:8000/api/v1/rest-auth/login/
Using the URLconf defined in blog_project.urls, Django tried these URL patterns, in this order:

admin/
api/v1/ <int:pk>/
api/v1/
api-auth/
api/v1/rest-auth ^password/reset/$ [name='rest_password_reset']
api/v1/rest-auth ^password/reset/confirm/$ [name='rest_password_reset_confirm']
api/v1/rest-auth ^login/$ [name='rest_login']
api/v1/rest-auth ^logout/$ [name='rest_logout']
api/v1/rest-auth ^user/$ [name='rest_user_details']
api/v1/rest-auth ^password/change/$ [name='rest_password_change']
The current path, api/v1/rest-auth/login/, didn't match any of these.

settings.py内容

代码语言:javascript
复制
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # 3rd Party
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',

    # Apps
    'posts.apps.PostsConfig',
]

下面是我的urls.py的内容

代码语言:javascript
复制
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/', include('posts.urls')),
    path('api-auth/', include('rest_framework.urls')),
    path('api/v1/rest-auth', include('rest_auth.urls')),
]

我不知道代码出了什么问题。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-06-21 14:34:05

你的问题在这里。

代码语言:javascript
复制
path('api/v1/rest-auth', include('rest_auth.urls')),

您需要在URL字符串的末尾添加一个/,如下所示-

代码语言:javascript
复制
path('api/v1/rest-auth/', include('rest_auth.urls')),
票数 3
EN

Stack Overflow用户

发布于 2020-06-21 13:46:44

在你的urls.py中,你需要为api/v1/rest-auth/login/实现一个url。

票数 0
EN

Stack Overflow用户

发布于 2020-06-21 14:03:06

找到原因,只是在路径中缺少"/“。现在它工作得很好。path('api/v1/rest-auth/',include('rest_auth.urls'))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62494816

复制
相关文章

相似问题

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