[英]Why request.GET.get('tag', '') returns C rather than C++ in django GET request?
This is my code in django template:这是我在 Django 模板中的代码:
{% for tag in tags %}
<a href="{% url 'tag_find' %}?tag={{ tag }}" > {{ tag }}</a>
{% endfor %}
in view.py:在view.py中:
def tag_find(request):
page = request.GET.get('page', 1)
tag = request.GET.get('tag', '')
print('show_tag:', tag)
........
Some example are not working perfectly, like:一些示例无法完美运行,例如:
When tag is C++
then request.GET.get()
shows C
, when returning tag from template is Portraits&Caricatures
then request.GET.get()
shows Portraits
.当标签是
C++
request.GET.get()
显示C
,当从模板返回标签是Portraits&Caricatures
request.GET.get()
显示Portraits
。 I have no idea why request.GET()
cuts some part of text.我不知道为什么
request.GET()
剪切文本的某些部分。
You need to |urlencode
[Django-doc] the value for the tag, the +
character is used for spaces:您需要对[Django-doc]标签值进行
|urlencode
, +
字符用于空格:
{% for tag in tags %}
<a href="{% url 'tag_find' %}?tag={{ tag
|urlencode }}" > {{ tag }}</a>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.