16

내가 내 urls.py에서이 경로를 가지고 : 페이지가 현재의 경우 클래스 기반 일반 뷰에서 RequestContext에 액세스하는 방법은 무엇입니까?

archive_index_dict = { 
    'queryset': News.objects.filter(show=True), 
    'date_field': 'date', 
    'template_object_name': 'object_list', 
} 

... 

url(r'^$', 'django.views.generic.date_based.archive_index', 
     archive_index_dict, name='news_archive_index' 
    ), 

가 지금은 템플릿에 감지 할 (이 메뉴 스타일입니다). {{ request.path }}이나 {{ request.get_full_path }}도 템플릿에서 작동하지 않습니다.

대신 무엇을 사용해야합니까?

솔루션

것은 내가 TEMPLATE_CONTEXT_PROCESSORSdjango.core.context_processors.request를 추가했다 템플릿 request 사용할 수 얻으려면. 이것은 기본적으로 설정되지 않습니다 (django 1.3부터).

+0

'django .... request' 컨텍스트 프로세서를 설정 했습니까? 거의 모든 CBV는 기본적으로'RequestContext'를 사용합니다. 물론 – ilvar

+0

OMG! :) 힌트를 가져 주셔서 감사합니다. 설정에서''django.core.context_processors.request ''를 추가했으며 템플릿에서'request'를 사용할 수 있습니다. BTW, 당신은 대답으로 귀하의 의견을 게시 할 수 있고 그것을 위해 투표거야. –

답변

20

'django.core.context_processors.request' 컨텍스트 프로세서를 설정 했습니까? 거의 모든 CBV는 기본적으로 RequestContext을 사용합니다.