(我有一个自定义用户模型)
我不明白为什么会这样。这些是我期望的网址:
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
仅通过导入来修改网址 ?