djangoプロジェクトにいくつかのスキーマビューを追加しようとしています(この例を使用しました)
私のコード:
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 /に接続しようとすると、エラーが発生します。
HTTP 403 Forbidden
Allow: GET, HEAD, OPTIONS
Content-Type: application/coreapi+json
Vary: Accept
{
"detail": "You do not have permission to perform this action."
}
私自身、エラーが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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加