I am trying to route all unknown URLs to a single view. However, in doing this my known URLs only work when they do not have a trailing slash, despite setting APPEND_SLASH
to True
in "settings.py".
Here is some code:
settings.py:
APPEND_SLASH = True
ADMIN_URL = "admin/"
urls.py:
from django.conf import settings
from django.contrib import admin
from django.urls import include, path, re_path
from myapp.views import my_catch_all_view
urlpatterns = [
path(settings.ADMIN_URL, admin.site.urls),
re_path(r"^.*", my_catch_all_view),
]
If I go to "localhost:8000", I correctly get routed to my catch-all view.
And if I go to "localhost:8000/foobar/", I correctly get routed to my catch-all view.
And if I go to "localhost:8000/admin/", I correctly get routed to the admin view.
But, if I go to "localhost:8000/admin", I incorrectly get routed to my catch-all view.
I have seen this answer, but unfortunately that doesn't work for me.
Any suggestions?