简体   繁体   English

Django管理模板:访问模板中的请求对象

[英]Django admin template: Accessing request object in template

I need the request object in all admin templates. 我需要所有管理模板中的请求对象。 In frontend templates, I can achieve this by rendering the template with RequestContext : 在前端模板中,我可以通过使用RequestContext呈现模板来实现此目的:

return render_to_response('my_template.html',
    my_data_dictionary,
    context_instance=RequestContext(request)
)

With that, I can access the request object in frontend: 有了它,我可以在前端访问请求对象:

{{ request.path }}

How can I do this for all admin views in Django 1.2? 如何在Django 1.2中为所有管理员视图执行此操作?

如果您在settings.py TEMPLATE_CONTEXT_PROCESSORS中添加了'django.core.context_processors.request'则应该可以在管理模板中使用该请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM