具有动态休息视图会复制用户列表网址

时间:2018-11-21 16:27:06

标签: python django django-rest-framework dynamic-rest

(我有一个自定义用户模型)

我不明白为什么会这样。这些是我期望的网址:

python manage.py show_urls
/api/v1/        rest_framework.routers.APIRootView      api-root
/api/v1/\.<format>/     rest_framework.routers.APIRootView      api-root
/api/v1/users/  users.views.UserCreateViewSet   user-list
/api/v1/users/<pk>/     users.views.UserViewSet user-detail
/api/v1/users/<pk>\.<format>/   users.views.UserViewSet user-detail
/api/v1/users\.<format>/        users.views.UserCreateViewSet   user-list

一旦我在urls.py中加入了基于DynamicModelViewSet的视图,便会出现:

from dynamic_rest.viewsets import DynamicModelViewSet


class AggregateViewSet(DynamicModelViewSet):
    pass

我的user-list网址已重复:

» python manage.py show_urls
/api/v1/        rest_framework.routers.APIRootView      api-root
/api/v1/\.<format>/     rest_framework.routers.APIRootView      api-root
/api/v1/users/  users.views.UserCreateViewSet   user-list
/api/v1/users/  users.views.UserViewSet user-list
/api/v1/users/<pk>/     users.views.UserViewSet user-detail
/api/v1/users/<pk>\.<format>/   users.views.UserViewSet user-detail
/api/v1/users\.<format>/        users.views.UserCreateViewSet   user-list
/api/v1/users\.<format>/        users.views.UserViewSet user-list

这是我的(简体)urls.py

from django.urls include
from rest_framework.routers import DefaultRouter

# from consumption.views import AggregateViewSet

router = DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'users', UserCreateViewSet)

urlpatterns = [
    path('api/v1/', include(router.urls)),
]

激活该from consumption.views import AggregateViewSet语句会使问题出现。它甚至不需要注册到路由器:仅导入视图就破坏了URL。

为什么dynamic-rest仅通过导入来修改网址

0 个答案:

没有答案