Django 无法在 URLConf 中找到 url 模式,尽管它已定义

发布于 2024-09-14 18:55:16 字数 1761 浏览 3 评论 0原文

我在浏览器中输入以下网址:

http://localhost:8000/en/weblog/2010/aug/10/wie-baue-ich-ein-weblog/

我收到“页面未找到(404)”错误,尽管第 10 个条目

(r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict),

我的 URLConf 中应该匹配。

唯一的区别是语言的前缀,但这不会影响其他模式,那么为什么它只影响这个呢。 (所有 urlpatterns 都匹配,除了上面的)

我的 UrlConf 看起来像这样:

urls.py

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

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

from blog.models import Entry

urlpatterns = patterns('preview.views',
    (r'^admin/(.*)', admin.site.root),
    (r'^$', 'home'),
    (r'^about_me.html/', 'show_about_me'),
    (r'^study.html/', 'show_study'),
    (r'^profile.html/', 'show_profile'),
    (r'^blog.html/', 'show_blog'),
    (r'^contact.html/', 'show_contact'),
    (r'^impressum.html/', 'show_impressum'),
)

entry_info_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    }

urlpatterns += patterns('',
    (r'^weblog/$', 'webpage.blog.views.entries_index'),
    (r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict),
)

if settings.DEBUG:
    urlpatterns += patterns('', 
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root' : os.path.join(settings.CURRENT_PATH, 'static') }),
)

有什么问题。我感谢任何帮助,

最诚挚的问候。

I type the following url in my browser:

http://localhost:8000/en/weblog/2010/aug/10/wie-baue-ich-ein-weblog/

an I get a "Page Not Found (404)" error, although the 10th entry

(r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

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

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

from blog.models import Entry

urlpatterns = patterns('preview.views',
    (r'^admin/(.*)', admin.site.root),
    (r'^

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py


What is the problem. I appreciate any help,

Best regards.

, 'home'), (r'^about_me.html/', 'show_about_me'), (r'^study.html/', 'show_study'), (r'^profile.html/', 'show_profile'), (r'^blog.html/', 'show_blog'), (r'^contact.html/', 'show_contact'), (r'^impressum.html/', 'show_impressum'), ) entry_info_dict = { 'queryset': Entry.objects.all(), 'date_field': 'pub_date', } urlpatterns += patterns('', (r'^weblog/

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

What is the problem. I appreciate any help,

Best regards.

, 'webpage.blog.views.entries_index'), (r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict), ) if settings.DEBUG: urlpatterns += patterns('', (r'^static/(?P<path>.*)

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

What is the problem. I appreciate any help,

Best regards.

, 'django.views.static.serve', { 'document_root' : os.path.join(settings.CURRENT_PATH, 'static') }), )

What is the problem. I appreciate any help,

Best regards.

, 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

What is the problem. I appreciate any help,

Best regards.

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

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

发布评论

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

评论(1

少女的英雄梦 2024-09-21 18:55:16

您的模式与 URL 不匹配:

>>> import re
>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/

这是因为您的模式中有拼写错误。您有 P?,它应该是 ?P

>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/

>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/'
>>> print re.match(pattern,url)
None

这是因为您的模式中有拼写错误。您有 P?,它应该是 ?P



>>> print re.match(pattern,url)
<_sre.SRE_Match object at 0x00B274F0>
>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/' >>> print re.match(pattern,url) None

这是因为您的模式中有拼写错误。您有 P?,它应该是 ?P

Your pattern doesn't match the URL:

>>> import re
>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/

It's because you have a typo in the pattern. You have P?<slug> and it should be ?P<slug>:

>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/

>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/'
>>> print re.match(pattern,url)
None

It's because you have a typo in the pattern. You have P?<slug> and it should be ?P<slug>:



>>> print re.match(pattern,url)
<_sre.SRE_Match object at 0x00B274F0>
>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/' >>> print re.match(pattern,url) None

It's because you have a typo in the pattern. You have P?<slug> and it should be ?P<slug>:

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