首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析“{request.LANGUAGE_CODE}”中的“{request.LANGUAGE_CODE}”余数

无法解析“{request.LANGUAGE_CODE}”中的“{request.LANGUAGE_CODE}”余数
EN

Stack Overflow用户
提问于 2017-10-19 03:52:40
回答 2查看 410关注 0票数 0

我用django 1.11编程,现在我有了下面的post_list.html脚本

代码语言:javascript
复制
{% with lang={{request.LANGUAGE_CODE}} %}
{% endwith %}

           <p>
               {% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
           </p>

但我不能得到朗实际上与以下错误信息,请help.Thanks。

代码语言:javascript
复制
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']

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-19 04:00:09

{% %}中不需要使用双花括号,而只需使用以下变量:

代码语言:javascript
复制
{% with lang=request.LANGUAGE_CODE %}
{% endwith %}
<p>
    {% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>

您可以在django模板指南中阅读更多有关这方面的内容。

票数 1
EN

Stack Overflow用户

发布于 2017-10-19 12:16:05

代码语言:javascript
复制
{% with lang=request.LANGUAGE_CODE %}
    <p>
        {% if lang == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
    </p>
{% endwith %}

但你可以简化它:

代码语言:javascript
复制
<p>
    {% if request.LANGUAGE_CODE == 'zh-CN' %} {{object.category.name_zh_CN}} {% else %} {{object.category.name}} {% endif %}
</p>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46822563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档