我有以下在 url 中传递的变量:
http://localhost:8000/diff/?Platform=Comcast&PlatformID=7066191365225244112#S8
我需要能够提取以下内容:
Platform = Comcast
PlatformID = 7066191365225244112#S8
但是,django 会转义 request.GET 字典中的散列。这是它显示的内容:
GET:<QueryDict: {u'PlatformID': [u'7066191365225244112'], u'Platform': [u'Comcast']}>,
我如何在此处捕获完整变量,包括末尾的 #S8?
请您参考如下方法:
在查询字符串中对它进行转义,基本上用 %23 替换 hash。
要在评论中回答您的问题,是的,有一个模板标签可以帮助您解决这个问题。语法是
{% url 'some-url-name' arg1=v1 arg2=v2 %}
或者,如果你想在代码中转义,你在https://docs.djangoproject.com/en/1.10/ref/utils/#module-django.utils.encoding中有几个选项。
