1

Django で動作する日付ベースのアーカイブの汎用ビューを取得しようとしています。チュートリアルで説明されているように URL を定義しましたが、変数 (月や年など) を含む URL にアクセスしようとすると、django は 404 エラーを返します。TemplateDoesNotExist-execption も生成しません。変数のない通常の URL は正常に機能します。

これが私の更新されたurlconfです:

from django.conf.urls.defaults import *
from zurichlive.zhl.models import Event

info_dict = {
        'queryset': Event.objects.all(),
        'date_field': 'date',
        'allow_future': 'True',
}

urlpatterns += patterns('django.views.generic.date_based',
    (r'events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug', template_name='archive/detail.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, template_name='archive/list.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$','archive_day',dict(info_dict,template_name='archive/list.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/$','archive_month', dict(info_dict, template_name='archive/list.html')),
    (r'^events/(?P<year>)/$','archive_year', dict(info_dict, template_name='archive/list.html')),
    (r'^events/$','archive_index', dict(info_dict, template_name='archive/list.html')),
)

/events/2010/may/12/this-is-a-slug/ にアクセスすると、detail.html テンプレートが表示されるはずですが、代わりに 404 が表示されます。何が間違っていますか?

そして、私はDjango 1.1.2を使用しています

4

2 に答える 2

2

正規表現のバックスラッシュを忘れました:

(r'events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$'

また、(正しく) スラッシュで終わる URL 正規表現を取得したので、URL は/events/2010/may/12/this-is-a-slug/.

于 2010-05-12T10:59:16.880 に答える
0

template_name をもう一度確認してください。

于 2010-05-15T13:33:40.293 に答える