문제

내 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 Regex에서 모든 것이 들어 있습니다 <brackets> 키워드 인수로 일반적인보기로 전달되고 있습니다.

문제는 당신이 사용하는 일반적인 견해입니다 (object_detail) 모든 주장 (즉, category).

Object_Detail Generic View에 대한 자세한 내용과 인수가 수락합니다.

필요한 경우 category 인수, Nick이 위에서 제안한대로보기를 포장하고 UrlConf에서 호출하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top