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

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

  解决方法:

  在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

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

解决方法:

用UltraEdit打开base.html和index.html、views.py等文件,然后保存为utf-8格式文件类型,替换原来的文件,问题可以解决。

参考网址,http://zerfew.blog.163.com/blog/static/19381016920149810440251/

3、提示:decoding Unicode is not supported

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

出错分析:代码里强制使用了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

相关文章:

  • 2022-01-21
  • 2021-08-11
  • 2021-06-11
  • 2021-06-18
  • 2022-02-07
  • 2021-06-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案