How to access RequestContext in class-based generic views?

元气小坏坏 提交于 2019-11-30 22:02:35

问题


I have this path in my urls.py:

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

Now I want to detect in template if a page is current (this is for menu styling). Neither {{ request.path }} nor {{ request.get_full_path }} work in template.

What should I use instead?

SOLUTION

To get request available in templates I had to add django.core.context_processors.request to TEMPLATE_CONTEXT_PROCESSORS. This is not set by default (since django 1.3).


回答1:


Do you have 'django.core.context_processors.request' context processor set up? Almost all CBV use RequestContext by default



来源:https://stackoverflow.com/questions/10162940/how-to-access-requestcontext-in-class-based-generic-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!