heberoxx 发表于 2015-4-25 07:04:24

Django笔记-字符编码相关问题整理

  1、添加中文注释后编译出错,提示:Non-ASCII

  解决方法:
  在Python脚本文件的第一行或第二行添加一句:
     #coding:gbk或#coding:utf-8或##-*- coding : gbk -*-
     参考网址:
     https://www.python.org/dev/peps/pep-0263/
  2、错误:'utf8' codec cant't decode byte 0xa1 in position 41:invalid start byte

  解决方法:
  用UltraEdit打开base.html和index.html、views.py等文件,然后保存为utf-8格式文件类型,替换原来的文件,问题可以解决。
  参考网址,http://zerfew.blog.163.com/blog/static/19381016920149810440251/
  3、提示:decoding Unicode is not supported

  出错分析:代码里强制使用了unicode字符集,去掉后就可以了





if uf.is_valid():   
username = uf.cleaned_data['username']
password = uf.cleaned_data['password']         
#username = unicode(uf.cleaned_data['username'],'UTF-8')
#password = unicode(uf.cleaned_data['password'],'UTF-8')
View Code  
页: [1]
查看完整版本: Django笔记-字符编码相关问题整理