Django rest: 您没有权限在创建api schem期间执行此操作

2024-04-26 01:23:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图向我的django项目添加一些模式视图(我使用了this示例)

我的代码:

def get_auth():
    auth = [
        path('', include('rest_framework.urls', namespace='rest_framework')),
        path('register', RegisterApiView),
        path('token/obtain/', TokenObtainPairView),
        path('token/refresh/', TokenRefreshView),
    ]
    return auth 

def get_schema():
    schema_url_patterns = [
        path('api/auth', include(get_auth())),
    ]

    schema_view = get_schema_view(
        title='Auth Schema',
        url='/api/auth/',
        patterns=schema_url_patterns,
    )
    return schema_view


urlpatterns = [
  path('api/auth/', get_schema()),
]

当我试图连接到/api/auth/时,遇到了一个错误:

^{pr2}$

Tags: pathdjangotokenauthviewrestapiurl
1条回答
网友
1楼 · 发布于 2024-04-26 01:23:57

修正了我自己的错误,错误在get_auth()方法中,我没有将as_view()添加到view类中:

def get_auth():
    auth = [
        path('', include('rest_framework.urls', namespace='rest_framework')),
        path('register', RegisterApiView.as_view({'post': 'create'})),
        path('token/obtain/', TokenObtainPairView.as_view()),
        path('token/refresh/', TokenRefreshView.as_view()),
        ]
    return auth

相关问题 更多 >