正则表达式参考手册
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.
[cce] >>> 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:[我是笑脸] ' [/cce]
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 :
[cce] LANG=en_US.UTF-8 LC_ALL="en_US.UTF-8" [/cce]
or you can type below to make the session take effect
[cce] export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8' [/cce]
python-django 部署
trouble shooting:
1.ImportError: Could not import settings ‘mysite.settings’ when deploying django? just add the following to the wsgi.py file:
[cce_ruby]
import sys
sys.path = [‘/home/mysite/prg/mysite/mysite_django’, ‘/home/mysite/prg/mysite’] + sys.path
[/cce_ruby]
2. you can confirm the problem by:
[cce_ruby] python >>>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 [/cce_ruby]
3. a config file of apache should like this:
[cce_ruby] <VirtualHost mysite.com:80> WSGIDaemonProcess mysite.com python-path=/usr/lib/python2.7/site-packages:/var/www/html/mysite/django WSGIScriptAlias / /var/www/html/mysite/django/mysite/wsgi.py ServerAdmin abc@gmail.com DocumentRoot /var/www/html/mysite/django ServerName mysite.com ErrorLog /var/log/httpd/apply.mysite.com-error.log CustomLog /var/log/httpd/apply.mysite.com-access.log combined <Directory /var/www/html/mysite/django> Order allow,deny Allow from all </Directory> </VirtualHost> [/cce_ruby]
reference from : http://stackoverflow.com/questions/8052559/how-to-troubleshoot-importerror-could-not-import-settings-mysite-settings-w
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’>
2.在http.conf中加入一个alias
Alias /media/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/
完!