How can I list urlpatterns (endpoints) on Django?

If you want a list of all the urls in your project, first you need to install django-extensions

You can simply install using command.

pip install django-extensions

For more information related to package goto django-extensions

After that, add django_extensions in INSTALLED_APPS in your settings.py file like this:

INSTALLED_APPS = (
...
'django_extensions',
...
)

urls.py example:

from django.urls import path, include
from . import views
from . import health_views

urlpatterns = [
    path('get_url_info', views.get_url_func),
    path('health', health_views.service_health_check),
    path('service-session/status', views.service_session_status)
]

And then, run any of the command in your terminal

python manage.py show_urls

or

./manage.py show_urls

Sample output example based on config urls.py:

/get_url_info             django_app.views.get_url_func
/health                   django_app.health_views.service_health_check
/service-session/status   django_app.views.service_session_status

For more information you can check the documentation.

Leave a Comment