gpt4 book ai didi

python - 如何在 django 中仅添加第三方应用程序所需的 url?

转载 作者:行者123 更新时间:2023-12-01 00:13:49 25 4
gpt4 key购买 nike

我的网址:我已经包含了第三方应用程序 django djoser 。有几个第三方应用程序的网址。但我只想要特定的。

urlpatterns = [
path('apis/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('apis/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('admin/', admin.site.urls),
path('auth/', include('djoser.urls')),
path("auth/", include("djoser.urls.jwt")),
]

这里是从 djoser 获取的所有 url。但我只想要一些网址并忽略其他网址。

^auth/ ^users/$ [name='user-list']
^auth/ ^users\.(?P<format>[a-z0-9]+)/?$ [name='user-list']
^auth/ ^users/activation/$ [name='user-activation']
^auth/ ^users/activation\.(?P<format>[a-z0-9]+)/?$ [name='user-activation']
^auth/ ^users/me/$ [name='user-me']
^auth/ ^users/me\.(?P<format>[a-z0-9]+)/?$ [name='user-me']
^auth/ ^users/resend_activation/$ [name='user-resend-activation']
^auth/ ^users/resend_activation\.(?P<format>[a-z0-9]+)/?$ [name='user-resend-activation']
^auth/ ^users/reset_password/$ [name='user-reset-password']
^auth/ ^users/reset_password\.(?P<format>[a-z0-9]+)/?$ [name='user-reset-password']
^auth/ ^users/reset_password_confirm/$ [name='user-reset-password-confirm']
^auth/ ^users/reset_password_confirm\.(?P<format>[a-z0-9]+)/?$ [name='user-reset-password-confirm']
^auth/ ^users/reset_username/$ [name='user-reset-username']
^auth/ ^users/reset_username\.(?P<format>[a-z0-9]+)/?$ [name='user-reset-username']
^auth/ ^users/reset_username_confirm/$ [name='user-reset-username-confirm']
^auth/ ^users/reset_username_confirm\.(?P<format>[a-z0-9]+)/?$ [name='user-reset-username-confirm']
^auth/ ^users/set_password/$ [name='user-set-password']
^auth/ ^users/set_password\.(?P<format>[a-z0-9]+)/?$ [name='user-set-password']
^auth/ ^users/set_username/$ [name='user-set-username']
^auth/ ^users/set_username\.(?P<format>[a-z0-9]+)/?$ [name='user-set-username']
^auth/ ^users/(?P<id>[^/.]+)/$ [name='user-detail']
^auth/ ^users/(?P<id>[^/.]+)\.(?P<format>[a-z0-9]+)/?$ [name='user-detail']
^auth/ ^$ [name='api-root']
^auth/ ^\.(?P<format>[a-z0-9]+)/?$ [name='api-root']

最佳答案

我想到的唯一选择是;

  1. 从 djoser UserViewSet 创建 subview 集:

    # views.py
    from djoser.views import UserViewSet

    class MyViewSet(UserViewSet):
    """Put your desired views and functions here"
  2. 然后将您的 View 添加到您的 urls.py

    from rest_framework.routers import DefaultRouter

    from .views import MyViewSet

    custom_router = DefaultRouter()
    router.register("users", MyViewSet)

    urlpatterns = [...] #your other urls

    urlpatterns += [url(r'/', include(custom_router.urls))]

希望这有帮助!

关于python - 如何在 django 中仅添加第三方应用程序所需的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59457941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com