奇怪的 Django URL 行为
我有以下 URL 配置:
urls.py
:
# ...
url(r'^test$', 'project.main.views.test', name='test'),
url(r'^app', include('project.app.urls')),
app/urls.py
:
# ...
url(r'^$', 'project.app.views.home', name='home'),
当导航到 example.com/test
时,我得到了正确的看法。但是,当 naivgating 到 example.com/app 时,我收到 404。如果重要的话,APPEND_SLASH
设置为 TRUE
。
将我的所有 URL 修复为以斜杠结尾可以解决此问题,但我不想让 URL 末尾带有那些无用的斜杠。
我缺少什么?
I have the following URL confs:
urls.py
:
# ...
url(r'^test
app/urls.py
:
# ...
url(r'^
When navigating to example.com/test
I get the proper view. But when naivgating to example.com/app
I get a 404. APPEND_SLASH
is set to TRUE
, if it matters.
Fixing all my URLs to end with a slash solves this, but I rather not have my URLs with those useless slashes at the end.
What am I missing?
, 'project.main.views.test', name='test'),
url(r'^app', include('project.app.urls')),
app/urls.py
:
When navigating to example.com/test
I get the proper view. But when naivgating to example.com/app
I get a 404. APPEND_SLASH
is set to TRUE
, if it matters.
Fixing all my URLs to end with a slash solves this, but I rather not have my URLs with those useless slashes at the end.
What am I missing?
, 'project.app.views.home', name='home'),
When navigating to example.com/test
I get the proper view. But when naivgating to example.com/app
I get a 404. APPEND_SLASH
is set to TRUE
, if it matters.
Fixing all my URLs to end with a slash solves this, but I rather not have my URLs with those useless slashes at the end.
What am I missing?
, 'project.main.views.test', name='test'), url(r'^app', include('project.app.urls')),app/urls.py
:
When navigating to example.com/test
I get the proper view. But when naivgating to example.com/app
I get a 404. APPEND_SLASH
is set to TRUE
, if it matters.
Fixing all my URLs to end with a slash solves this, but I rather not have my URLs with those useless slashes at the end.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我的
PYTHONPATH
中有一些损坏的模块,它以某种方式弄乱了整个 url conf。当在干净的环境中工作时(即使用
virtualenv
),一切都运行良好。It turns out there's some corrupt module in my
PYTHONPATH
which somehow messes up the entire url conf.When working from a clean environment (i.e. using
virtualenv
), everything works great.