I'm setting up a new tests, and i want to make an reverse.
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()
So , i want make a reverse in tests.py. my shot is:
CREAT_USER_URL = reverse('profile-create')
And I simply get:
Reverse for 'profile-create' not found. 'profile-create' is not a valid view function or pattern name.
How should I set up a reverse in this case.
You should use profile-list
instead of profile-create
CREAT_USER_URL = reverse('profile-list')
There is no URL as {base_name}-create
, If you wanna use create endpoint, use {base_name}-list
.
For more information, refer to this table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With