Django 无法在 URLConf 中找到 url 模式,尽管它已定义
我在浏览器中输入以下网址:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的模式与 URL 不匹配:
>>> 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:
>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/' >>> print re.match(pattern,url) NoneIt's because you have a typo in the pattern. You have
P?<slug>
and it should be?P<slug>
: