Django无需使用"request.path"即可获取网址路径. [英] Django get url path without using "request.path"

查看:155
本文介绍了Django无需使用"request.path"即可获取网址路径.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在django中创建一个404.html页面,当我举起"Http404"时将被调用

I am creating a 404.html page in django which will be called when i raise "Http404"

我不知道404.html是否将传递给"RequestContext"对象,但是我可以在不使用请求变量的情况下生成请求的url路径

I dont know if 404.html will be passed a "RequestContext" object but can I generate the requested url path without using request variable

我尝试了"request.path"和"request.get_full_path",但它们对我不起作用.

I tried "request.path" and "request.get_full_path" but they dont work for me.

任何帮助将不胜感激.

推荐答案

将使用请求上下文(不同于500服务器错误模板)呈现404模板 .

The 404 template will be rendered with a request context (unlike the 500 server error template).

确保 django.core.context_processors.request 上下文处理器位于您的TEMPLATE_CONTEXT_PROCESSORS设置中.请注意,默认情况下不包含它.

Make sure that the django.core.context_processors.request context processor is in your TEMPLATE_CONTEXT_PROCESSORS setting. Note that it is not included by default.

完成此操作后,请求方法get_full_path这样的>应该起作用.

Once you've done that, the request methods that you mention like get_full_path should work.

这篇关于Django无需使用"request.path"即可获取网址路径.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆