奇怪的 Django URL 行为

发布于 2024-12-05 11:34:47 字数 526 浏览 1 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

時窥 2024-12-12 11:34:47

事实证明,我的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文