resolve Emoji Emotion symbols when save to mysql<5.5

1. what’s Emoji Emotion symbols: it’s usually post by iPhone client;

2. when the content include a Emoji from API, it’s always a [] like “[]晚安俩宝”, actually it is a moon emotion, but when you insert it into a utf-8 mysql database , you will get a warning as: “Incorrect string value: ‘\xF0\x9F\x94\x8E’ for column ‘line’ at row 1.

The string ‘\xF0\x9F\x91\x8A, actually is a 4-byte unicode: u’\U0001f62a’, but utf-8 database could not accept a 4-byte, mysql under 5.5.3 don’t support 4-byte unicode.

3. using re.compile method you could replace all the 4-byte unicode to something you want.

>>> import re
>>> highpoints = re.compile(u'[\U00010000-\U0010ffff]')
>>> example = u'Some example text with a sleepy face: \U0001f62a'
>>> highpoints.sub(u'[我是笑脸]', example)
u'Some example text with a sleepy face:[我是笑脸] '

here the "\U0001f62a" is just a Emoji smile face.
you can print that in python shell to confirm that.
4. if still can't print, check your Locale settings by tpye: locale
be sure to set :
or you can type below to make the session take effect
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

python-django 部署

trouble shooting:

1.ImportError: Could not import settings ‘mysite.settings’ when deploying django? just add the following to the file:
import sys
sys.path = [‘/home/mysite/prg/mysite/mysite_django’, ‘/home/mysite/prg/mysite’] + sys.path


2. you can confirm the problem by:
>>>import sys
>>>print sys.path
# you will find there is no directory of your django root. that's the problem
>>> sys.path = ['/home/mysite/prg/mysite/mysite_django', '/home/mysite/prg/mysite'] + sys.path
>>>import mysite_django.settings
# this should be no errors 
3. a config file of apache should like this:
    WSGIDaemonProcess python-path=/usr/lib/python2.7/site-packages:/var/www/html/mysite/django
    WSGIScriptAlias / /var/www/html/mysite/django/mysite/
    DocumentRoot /var/www/html/mysite/django
    ErrorLog /var/log/httpd/
    CustomLog /var/log/httpd/ combined
    <Directory /var/www/html/mysite/django>
        Order allow,deny
        Allow from all

reference from :

python django admin with no css[solved]

问题: django运行在本地, 默认的后台管理只要/admin, 即可正常访问, 扔到服务器上以后由于路径问题, django自带的media文件就无法被正确加载;

官方有很多说法, 这里提供一种最为简便的方法:

1. 找到django的中负责css的文件目录, 是static或者media路径

  • 如何找到你的django在何处:
  • python>
  • python>import django
  • python>django
  • <module ‘django’ from ‘/usr/local/lib/python2.7/dist-packages/django/__init__.pyc’>


Alias /media/