Reputation: 14154
Working with the Django-powered project that would automatically put a trailing slash at the end. So:
foo.com/bar
would become a
foo.com/bar/
I have read that there is a CommonMiddleware
class which has an APPEND_SLASH
attribute with which trailing slash can be controlled. My project import CommonMiddleware
indeed:
MIDDLEWARE_CLASSES = (
...
'django.middleware.common.CommonMiddleware',
)
However APPEND_SLASH
is never set anywhere. And the project keeps adding trailing slash.
Question: does APPEND_SLASH
get set to True
by default if you import CommonMiddleware
? Are there any ways to control the trailing slash?
Upvotes: 1
Views: 2854
Reputation: 14154
I will compile a full answer. It has 2 aspects:
1) If you import CommonMiddleware
into your project - it would use its APPEND_SLASH
attribute (which is True
by default).
2) Keep track of your urls file (if it is something like ^foo.com/bar/$
).
And don't forget to clear the cache if you change CommonMiddleware
or APPEND_SLASH
(since browser will most likely cache it).
Upvotes: 1
Reputation: 2054
I think you have to set APPEND_SLASH
in your django settings module.
https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-APPEND_SLASH
Upvotes: 4