python 如何从 Django 请求对象访问 url 哈希/片段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2181186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 23:59:21  来源:igfitidea点击:

How to access url hash/fragment from a Django Request object

pythondjangohashdjango-urlsfragment-identifier

提问by Andrea Zilio

As in the title: How can I access the URL hash/fragment (the part following the hash #, or 'pound symbol' in US English) from a Django view and so, I suppose, from a Django Request object?

如标题所示:如何#从 Django 视图访问 URL 散列/片段(散列后面的部分,或美国英语中的“磅符号”),我想,从 Django 请求对象?

I've not found enough information on the documentation here available: http://docs.djangoproject.com/en/dev/ref/request-response/

我没有找到有关此处可用文档的足够信息:http: //docs.djangoproject.com/en/dev/ref/request-response/

P.S. Assume the fragment is included in the URL sent to the server. (I have verified this in my case, where I'm not actually using a browser.)

PS 假设该片段包含在发送到服务器的 URL 中。(我已经在我的案例中验证了这一点,我实际上没有使用浏览器。)

回答by Matthew Flaschen

This is not sent to the server, by definition. From URI References: Fragment Identifiers on URIs :

根据定义,这不会发送到服务器。来自URI 参考:URI 上的片段标识符

"The HTTP engine cannot make any assumptions about it. The server is not even given it."

“HTTP 引擎无法对此做出任何假设。服务器甚至没有给出它。”