Django get url path without using “request.path”

廉价感情. 提交于 2019-12-07 15:55:23

问题


I am creating a 404.html page in django which will be called when i raise "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

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

Any help would be appreciated.


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/10037200/django-get-url-path-without-using-request-path

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