这是我的urls.py
:
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
如果我在浏览器 (Firefox) 中键入 127.0.0.1:8000/polls
,我将被重定向到 127.0.0.1:8000/polls/
(在斜杠处结束)。
老实说,我很困惑为什么会这样。因为在我的settings.py
里面没有
APPEND_SLASH = True
但是,Django 文档说:
APPEND_SLASH
Default: True
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.
来源:https://docs.djangoproject.com/en/1.11/ref/settings/#append-slash
APPEND_SLASH 是否默认为 True,即使它不在 settings.py
中?如果你想将它设置为 False,你应该只把它放在这个文件中?
或者这种行为的原因是什么?
最佳答案
是的,默认是True
,所以如果你没有在你的设置文件中提供它,它将是True
。
任何未在您的设置文件中定义的设置都将使用默认值,默认值在django.conf.global_settings
中提供。 .
关于python - Django:即使不在 settings.py 中,APPEND_SLASH 是否设置为 True?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45784191/