zoukankan      html  css  js  c++  java
  • Django 2.2_错误:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

      环境说明

      1.开发系统: windows

      2.IDE: pycharm  

      3.数据库: msyql,navicat

      4.编程语言: python3.7  (Windows x86-64 executable installer)

      5.虚拟环境: virtualenvwrapper

      6.开发框架: Django 2.2

    访问admin出现问题:

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

    解决方法:

    1.直接点击下面这个错误提示,进入到debug.py文件,前在目录可能不一样(这是我项目虚拟环境的路径F:\CMCT\A01CMCT\study\Aenv\A02cabj).

    # 错误显示
    File "F:\CMCT\A01CMCT\study\Aenv\A02cabj\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html 
    1 def get_traceback_html(self):
    2     """Return HTML version of debug 500 HTTP error page."""
    3     with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:
    4         t = DEBUG_ENGINE.from_string(fh.read())
    5     c = Context(self.get_traceback_data(), use_l10n=False)
    6     return t.render(c) 

    2.在  open()  中加入  encoding = 'utf-8'  ===>  open(encoding = 'utf-8')  注意中间的引号,如果还报错就再重新输入一下两边的引号

    1 def get_traceback_html(self):
    2     """Return HTML version of debug 500 HTTP error page."""
    3     with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding = 'utf-8') as fh:
    4        t = DEBUG_ENGINE.from_string(fh.read())
    5     c = Context(self.get_traceback_data(), use_l10n=False)
    6     return t.render(c)

     3.重启项目再进入admin

  • 相关阅读:
    TCP/IP 网路基础
    三、Django之请求与响应-Part 1
    二、Django快速安装
    Linux 优化详解
    缓存的正确使用方式
    HTML从入门到放弃
    Ansible开发之路
    程序猿数据库学习指南
    MySQL错误代码大全
    Python之网络编程
  • 原文地址:https://www.cnblogs.com/djtang/p/10194811.html
Copyright © 2011-2022 走看看