昨天Django1.9发布了,今天我才刚开始学习Django,然后有一个问题就卡住了——如何支持中文?上网上查了好多资料都不好使,最后我搜索Django文件夹才发现,在1.9版本里,简体中文代码是zh_Hans,繁体中文代码是zh_Hant
就是这样,白白折腾了好久。。。
细节:
1)将
‘django.middleware.locale.LocaleMiddleware’,
添加到
django.contrib.sessions.middleware.SessionMiddleware
下面那行,如
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
2)修改LANGUAGE_CODE参数设为 ‘zh-Hans’
LANGUAGE_CODE = ‘zh-Hans’
转自http://blog.csdn.net/zmhawk/article/details/50154361