Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 如何在DefaultRouter()中进行反转_Django_Django Rest Framework - Fatal编程技术网

Django 如何在DefaultRouter()中进行反转

Django 如何在DefaultRouter()中进行反转,django,django-rest-framework,Django,Django Rest Framework,我正在设置一个新的测试,我想做一个相反的测试 router = DefaultRouter() router.register('profile', views.UserProfileViewSet, base_name='profile') urlpatterns = [ url(r'', include(router.urls)) ] UserProfileViewSet class UserProfileViewSet(viewsets.ModelViewSet): """

我正在设置一个新的测试,我想做一个相反的测试

router = DefaultRouter()
router.register('profile', views.UserProfileViewSet, base_name='profile')

urlpatterns = [
   url(r'', include(router.urls))
]
UserProfileViewSet

class UserProfileViewSet(viewsets.ModelViewSet):
   """Handles creating, creating and updating profiles."""

   serializer_class = serializers.UserProfileSerializer
   permission_classes = (permissions.UpdateOwnProfile,)
   authentication_classes = (TokenAuthentication,)

   queryset = get_user_model().objects.all()
所以,我想在tests.py中做一个反向。我的目标是:

CREAT_USER_URL = reverse('profile-create')
我只得到:

找不到“配置文件创建”的反向项“配置文件创建”不是有效的视图函数或模式名称


在这种情况下,我应该如何设置反转。

您应该使用
配置文件列表
而不是
配置文件创建

create\u USER\u URL=reverse('profile-list')

没有URL作为
{base\u name}-create
,如果要使用create endpoint,请使用
{base\u name}-list


有关详细信息,请添加
UserProfileViewSet
view?/谢谢,我在url.py中使用了app_name,这就是为什么首次配置文件列表对我不起作用的原因