Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not use unicode string in django template

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: enter image description here

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

like image 536
Duy Trần Avatar asked Nov 23 '15 08:11

Duy Trần


2 Answers

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.

like image 162
Rahul Avatar answered Sep 20 '22 14:09

Rahul


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">

like image 34
Tarun Behal Avatar answered Sep 24 '22 14:09

Tarun Behal