I'm using django admin on my website. When I enter url without slash after admin (http://example.com/admin) I receive 404 error. I thought that django automatically added slash on the end of url. Of course when I enter url ended with slash it works fine. What I am doing wrong, or which settings I have to change. Thanks for any ideas.
2 Answers
Try setting APPEND_SLASH = True in settings.py.
On second thoughts, I think the default setting is True.
https://docs.djangoproject.com/en/dev/ref/settings/#append-slash
7 Comments
Don't forget the CommonMiddleware in your settings.py:
It's important to remember that the APPEND_SLASH parameter works in conjunction with the 'django.middleware.common.CommonMiddleware'. So in order for it to work you should have the following in your settings.py:
MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
]
You don't need to add the APPEND_SLASH in your settings.py because the default behavior is to redirect URLs that you've typed without and ending slash, for the correct one and as a pattern, you should always write your URLs with an ending slash, like:
urlpatterns = [
path('hello/', views.hello_world),
]