URL names must be unique otherwise reverse('url_name') and {% url 'url_name' %} will link to the "wrong" page half of the time.

Django uses the URL name to generate the view's URL. Like a dict, only one entry can exist for a given "key".

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
urls.py
1
+
urlpatterns = [
2
+
    path('', Home.as_view(), name="index"),
3
+
    path('index/', Index.as_view(), name="index"),
Suggested changes
-
    path('index/', Index.as_view(), name="index"),
+
    path('index/', Index.as_view(), name="index-list"),
Commit suggestion

URL names must be unique otherwise reverse('url_name') and {% url 'url_name' %} will link to the "wrong" page half of the time.

Read more
4
+
]
Update urls.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code non-unique-url-name in your pyproject.toml file.

Read more about configuring Code Review Doctor.