[英]Django get url path without using "request.path"
I am creating a 404.html page in django which will be called when i raise "Http404"我正在 django 中创建一个 404.html 页面,当我提出“Http404”时将调用该页面
I dont know if 404.html will be passed a "RequestContext" object but can I generate the requested url path without using request variable我不知道 404.html 是否会传递一个“RequestContext”object 但我可以在不使用请求变量的情况下生成请求的 url 路径
I tried "request.path" and "request.get_full_path" but they dont work for me.我尝试了“request.path”和“request.get_full_path”,但它们对我不起作用。
Any help would be appreciated.任何帮助,将不胜感激。
The 404 template will be rendered with a request context (unlike the 500 server error template). 404 模板将使用请求上下文呈现(与 500 服务器错误模板不同)。
Make sure that the django.core.context_processors.request
context processor is in your TEMPLATE_CONTEXT_PROCESSORS
setting.确保django.core.context_processors.request
上下文处理器在您的TEMPLATE_CONTEXT_PROCESSORS
设置中。 Note that it is not included by default.请注意,默认情况下不包含它。
Once you've done that, the request methods that you mention like get_full_path
should work.一旦你这样做了,你提到的像get_full_path
这样的请求方法应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.