下面是我的URL模式:

news_info_month_dict = {
    'queryset': Entry.published.filter(is_published=True),
    'date_field': 'pub_date',
    'month_format': '%m',
}

(r'^(?P<category>[-\w]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+).html$', 
    'object_detail', news_info_month_dict, 'news_detail'),

但是他们有一个错误喜欢这样的:

object_detail() got an unexpected keyword argument 'category'

请帮助我。谢谢!

有帮助吗?

解决方案

我认为你必须写自己的观点代替通用object_detail的,是这样的(未经测试)

import datetime

def view_entry(request, category, year, month, day, slug):
    date = datetime.date(int(year), int(month), int(day))
    entry = get_object_or_404(Entry, slug=slug, date=date, is_published=True, category=category)
    return render_to_response('news_detail', {'object': entry})

虽然有可能与object_detail做到这一点,我不知道 - 我很少使用通用视图

其他提示

在你的URL的正则表达式,一切都在<brackets>是越来越传递到普通视图作为关键字参数。

问题是,你使用(object_detail)通用视图不支持所有的这些参数(即,category)。

关于通用object_detail并视图,它接受参数的更多信息。

如果你需要一个category的说法,只是包装的观点尼克上述建议,并呼吁从你的URLconf。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top