Is it possible to write a view for the endpoint 'auth/users/'?

I’ve just tried writing a view for the endpoint ‘auth/users’, as I want something other than the generic Django API page that shows up for it.

It doesn’t appear to be writable, though? Although I wrote a view, template and a path linking the view to the url, it just leads to the generic API page.

I have spent a good amount of time searching around, but I can’t find much info on the topic.

All I want to know is whether it can be, or not.

Thanks in advance.

Yes, you can override any url. Url definitions are searched in the order defined, so if you want to define a url overriding a system url, your app needs to be before the system app in INSTALLED_APPS.

Hi Ken,

Thanks for your reply.

Do you mean that I should move the app ‘restaurant’ above those of Djoser and the Rest Framework in INSTALLED_APPS?

This is what I have at the moment. I thought it was standard practice to put apps after installed packages in INSTALLED_APPS?

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'djoser',
    'restaurant',
]

I’ve just moved the custom view url pattern for ‘auth/users/’ above the include(‘djoser.urls’) and it works now.

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('restaurant.urls')),
    path('', include(router.urls)),
    path('', include('django.contrib.auth.urls')),
    path('auth/users/', views.signup.as_view(), name='sign-up'),
    path('auth/', include('djoser.urls')),
    path('auth/', include('djoser.urls.authtoken')),
    path('api-token-auth/', obtain_auth_token),
]

Do I need to put my restaurant app above Djoser and Rest Framework in INSTALLED_APPS, then, or not?

Thanks again! :slight_smile:

No, it is not. There are a couple of areas where the order of the entries in it is important, where that order defines some type of sequencing of internal operations. (Template search being another example.) It’s a requirement to order those entries in the order needed for your purposes. If you need your apps listed first, put them first. If you need some third-party apps first, put them first. So the ordering of entries is determined by need, not by some common convention.

Thanks for the help, Ken.