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".
So in practice, do this
# in urls.py
urlpatterns = [
path('', Home.as_view(), name="home"),
path('my-fox-holes/', MyFoxHoles.as_view(), name="my-fox-hole"),
]
Instead of this
# in urls.py
urlpatterns = [
path('', Home.as_view(), name="home"),
path('my-fox-holes/', MyFoxHoles.as_view(), name="home"),
]
Django 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.