[Fixed]-Django: Is APPEND_SLASH set to True even if not in settings.py?

20👍

Yes, the default is True, so if you don’t provide it in your settings file it will be True.

Any setting that is not defined in your settings file will use the default value, which is provided in django.conf.global_settings.

👤knbk

2👍

In your settings.py in the installed apps you might notice you have CommonMiddleware

This middleware takes care of adding ‘/’ to the end of URLs.

Snippet from the documentation:

class CommonMiddleware[source]

Adds a few conveniences for perfectionists:

Forbids access to user agents in the DISALLOWED_USER_AGENTS setting, which should be a list of compiled regular expression objects.

Performs URL rewriting based on the APPEND_SLASH and PREPEND_WWWsettings.

If APPEND_SLASH is True and the initial URL doesn’t end with a slash, and it is not found in the URLconf, then a new URL is formed by appending a slash at the end. If this new URL is found in the URLconf, then Django redirects the request to this new URL. Otherwise, the initial URL is processed as usual.

For example, foo.com/bar will be redirected to foo.com/bar/ if you don’t have a valid URL pattern for foo.com/bar but do have a valid pattern for foo.com/bar/.

You can read more here :
https://docs.djangoproject.com/en/1.11/ref/middleware/

Leave a comment