Django 无法路由 url(简单问题)

发布于 2024-09-16 23:47:51 字数 954 浏览 7 评论 0原文

我正在做一些愚蠢的事情,而且我不确定那是什么。我的 django 项目的根目录中有以下 urls.py:

from django.conf.urls.defaults import *
from django.conf import settings

urlpatterns = patterns('',
    (r'^$', include('preview_signup.urls')),
)

在我的 Preview_signup 模块(django 应用程序)中,我有以下 urls.py 文件:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^thanks/$', 'direct_to_template', {'template': 'thankyou.html'})
)

当我转到 http://localhost:8000/thanks/。但如果改为这样:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^$', 'direct_to_template', {'template': 'thankyou.html'})
)

我转到 http://localhost:8000/ 它工作正常。

我做错了什么?

I'm doing something stupid, and I'm not sure what it is. I have a the following urls.py in the root of my django project:

from django.conf.urls.defaults import *
from django.conf import settings

urlpatterns = patterns('',
    (r'^

In my preview_signup module (django app) I have the following urls.py file:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^thanks/

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, include('preview_signup.urls')), )

In my preview_signup module (django app) I have the following urls.py file:


The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:


And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, 'direct_to_template', {'template': 'thankyou.html'}) )

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:


And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, include('preview_signup.urls')), )

In my preview_signup module (django app) I have the following urls.py file:

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, 'direct_to_template', {'template': 'thankyou.html'}) )

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, include('preview_signup.urls')), )

In my preview_signup module (django app) I have the following urls.py file:

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, 'direct_to_template', {'template': 'thankyou.html'}) )

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

, include('preview_signup.urls')), )

In my preview_signup module (django app) I have the following urls.py file:

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

鱼忆七猫命九 2024-09-23 23:47:51

此代码应该有效:

urlpatterns = patterns('',
    (r'^', include('preview_signup.urls')),
)

$(行尾)刚刚删除。

This code should work:

urlpatterns = patterns('',
    (r'^', include('preview_signup.urls')),
)

$ (end of line) just removed.

如痴如狂 2024-09-23 23:47:51

当出现问题时(或者即使没有出现问题),请仔细阅读 django 文档。以下是上述链接的摘录:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^weblog/',        include('django_website.apps.blog.urls.blog')),
    (r'^documentation/', include('django_website.apps.docs.urls.docs')),
    (r'^comments/',      include('django.contrib.comments.urls')),
)

请注意,正则表达式
这个例子没有 $
(字符串结尾匹配字符)但是
包括尾部斜杠。每当
Django遇到include(),它砍了
关闭 URL 匹配的任何部分
到那时并发送
剩余的字符串包含在内
URLconf 进行进一步处理。

When something goes wrong (or even if it doesn't), thoroughly read the django docs. Here's an excerpt from the aforementioned link:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^weblog/',        include('django_website.apps.blog.urls.blog')),
    (r'^documentation/', include('django_website.apps.docs.urls.docs')),
    (r'^comments/',      include('django.contrib.comments.urls')),
)

Note that the regular expressions in
this example don't have a $
(end-of-string match character) but do
include a trailing slash. Whenever
Django encounters include(), it chops
off whatever part of the URL matched
up to that point and sends the
remaining string to the included
URLconf for further processing.

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