In my Django app I was wondering: why does the route with the url of "blog/" work but "blog" doesn't? Why is there a need to add the slash in the end? I am using Django 2.2.
Asked
Active
Viewed 260 times
0
-
Look at your urls.py. There's probably a / at the end of your pattern, so that's why a / is needed. – RemcoGerlich Jun 24 '19 at 07:53
-
Yeah this probably is a duplicate! Even tho the question was asked 9 years ago and Django was pretty different back then, this setting actually is still the same. – creyD Jun 24 '19 at 07:54
1 Answers
1
You are probably looking for the 'APPEND_SLASH' setting. It's included in the documentation here and it explains the why:
When set to True, if the request URL does not match any of the patterns in the URLconf and it doesn’t end in a slash, an HTTP redirect is issued to the same URL with a slash appended. Note that the redirect may cause any data submitted in a POST request to be lost.
The APPEND_SLASH setting is only used if CommonMiddleware is installed (see Middleware). See also PREPEND_WWW.