我用django 1.11编程,现在我有了下面的post_list.html脚本
{% with lang={{request.LANGUAGE_CODE}} %}
{% endwith %}
<p>
{% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>
但我不能得到朗实际上与以下错误信息,请help.Thanks。
TemplateSyntaxError at /adv/australia-strategic/
Could not parse the remainder: '{{request.LANGUAGE_CODE}}' from '{{request.LANGUAGE_CODE}}'
Request Method: GET
Request URL: http://localhost:8030/adv/australia-strategic/
Django Version: 1.11.6
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '{{request.LANGUAGE_CODE}}' from '{{request.LANGUAGE_CODE}}'
Exception Location: /Users/wzy/anaconda2/envs/python36/lib/python3.6/site-packages/django/template/base.py in __init__, line 700
Python Executable: /Users/wzy/anaconda2/envs/python36/bin/python
Python Version: 3.6.3
Python Path:
['/Users/wzy/expo3/expo',
'/Users/wzy/anaconda2/envs/python36/lib/python36.zip',
'/Users/wzy/anaconda2/envs/python36/lib/python3.6',
'/Users/wzy/anaconda2/envs/python36/lib/python3.6/lib-dynload',
'/Users/wzy/anaconda2/envs/python36/lib/python3.6/site-packages',
'/Users/wzy/expo3/expo']
发布于 2017-10-19 04:00:09
在{% %}中不需要使用双花括号,而只需使用以下变量:
{% with lang=request.LANGUAGE_CODE %}
{% endwith %}
<p>
{% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>您可以在django模板指南中阅读更多有关这方面的内容。
发布于 2017-10-19 12:16:05
{% with lang=request.LANGUAGE_CODE %}
<p>
{% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>
{% endwith %}但你可以简化它:
<p>
{% if request.LANGUAGE_CODE == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>https://stackoverflow.com/questions/46822563
复制相似问题