Skip to content Skip to sidebar Skip to footer

How Django Adds Trailing Slash

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 CommonM

Solution 1:

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


Solution 2:

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).


Post a Comment for "How Django Adds Trailing Slash"