【发布时间】:2020-10-20 00:01:58
【问题描述】:
我正在使用 Django Rest Framework 开发一个 REST API。
对于身份验证,我使用,
我现在知道如何为端点的特定视图设置身份验证。 但我找不到设置受保护的 URL 模式的方法。
例如,我有两个名为 an_app 和 another_app 的应用程序。
这是我项目的urls.py 文件。
from django.conf.urls import url
from django.urls import path, include
urlpatterns = [
path('auth/', include('dj_rest_auth.urls')),
path('auth/signup/', include('dj_rest_auth.registration.urls')),
path('public_contents/', include('an_app.urls')),
path('private_contents/', include('another_app.urls')),
]
这两个 URL - public_contents 和 private_contents 都无需身份验证即可访问。
我想让任何人都可以访问public_contents,并且想让拥有有效 JWT 令牌的用户可以访问private_contents。
我该怎么做?
【问题讨论】:
标签: python django authentication django-rest-framework