如何启用django模板unicode?

时间:2015-07-18 15:23:56

标签: django templates unicode

我需要帮助使django模板与unicode一起使用。 我在CENTOS 6.5上使用Django 1.8和python 2.7。使用utf-8创建MySQL数据库。当django渲染一些模板时,我收到错误:

UnicodeEncodeError at /
'ascii' codec can't encode character u'\xe9' in position 13: ordinal not in  range(128)
Request Method: GET
Request URL:    http://bluenanta.com:8000/
Django Version: 1.8.3
Exception Type: UnicodeEncodeError
Exception Value:    
'ascii' codec can't encode character u'\xe9' in position 13: ordinal not in range(128)
Exception Location: /home/bluenant/python/lib/python2.7/site-    packages/django/utils/encoding.py in force_text, line 94
Python Executable:  /home/bluenant/python/bin/python

=====================================

以下代码示例包含可能包含非ascii字符串的变量(例如image.species}}或{{image.foto}}

{% for image in random_list%}
   <li>{% if image.source_url %}
        <a href="{{image.source_url}}" target="_blank">{% endif %}
    <img src="{{ image.image_url }}" width="150"/>
    <br><font size=1px>{{image.id}} {{image.species}} {{image.variance}} 
    {%   if image.form %} forma {{image.form}}{% endif %}<br>
    {% if image.foto %} photo: {{image.foto}}{% endif %}
    {% if image.source_url %}</a>{% endif %}</font>
   </li>
{% endfor %}

0 个答案:

没有答案