views:

144

answers:

2

Here is my URL pattern:

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

and

(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'),

But they have an error likes this:

object_detail() got an unexpected keyword argument 'category'

Please help me. Thanks!

+3  A: 

I think you'll have to write your own view in place of the generic object_detail, something like this (untested)

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})

Though it may be possible to do it with object_detail I don't know - I very rarely use generic views.

Nick Craig-Wood
Sorry, function datetime.date does not accept variables. They want the integers.
Tran Tuan Anh
I fixed my post with some int(...)s that might work now!
Nick Craig-Wood
A: 

In your URL regex, everything in <brackets> is getting passed to the generic view as a keyword argument.

The problem is that the generic view you're using (object_detail) doesn't support all of those arguments (namely, category).

More information about the object_detail generic view and the arguments it accepts.

If you need a category argument, just wrap the view as Nick suggested above and call that from your URLconf.

John Debs