how to set django and mysql work with UTF-8

后端 未结 1 1868
孤独总比滥情好
孤独总比滥情好 2020-12-29 15:25

I want to set my Django/mysql site to work with UTF-8. Please guide me the changes I have to make in django and mysql to make sure the following things.

  1. Use

1条回答
  •  执念已碎
    2020-12-29 15:35

    here some advices:

    1) use utf8 encoding when creating database

    CREATE DATABASE  CHARACTER SET utf8;
    

    docs

    2) place the following special comment in the first or second lines of your script:

    # -*- coding: utf-8 -*-
    

    nice article about python and utf8

    3) Use unicode strings with u prefix in *.py files

    unicodeString = u"hello Unicode world!"
    

    4) Use follwing meta tag in section of your base template:

    
    

    0 讨论(0)
提交回复
热议问题