Can not use unicode string in django template

筅森魡賤 提交于 2019-12-07 07:16:22

问题


I used "BỘ MÔN TOÁN" string in django template it raised error "'utf8' codec can't decode byte 0xd4 in position 569: invalid continuation byte". But when I use "BO MON TOAN" string, it does'nt raise error. So, I used vietnamese in template and this is my code:

{% extends "site_base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load url from future %}

{% block body_base %}
     <div class="subject-box-title">
         BỘ MÔN TOÁN
     </div>
{% endblock %}

And this is error in my project:

What's happening in my project. Please help me, thanks!


回答1:


You can define into your HTML tag!

<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 

and then try to o/p the string.




回答2:


To debug the issue follow following steps:

  1. In your python files, declare the encoding # -*- coding: utf-8 -*-

  2. In your base html <meta http-equiv="Content-Type" content="text/html; charset=utf-8">



来源:https://stackoverflow.com/questions/33866503/can-not-use-unicode-string-in-django-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!