美文网首页
Django框架manage.py runserver 编码问题

Django框架manage.py runserver 编码问题

作者: 我拿buff谢谢 | 来源:发表于2017-08-22 17:55 被阅读0次

    #换了电脑重装了环境,发现Django的项目起不来,折腾了好久,才看到网上一帖子,做下记录。

    报错大概如下:

    #python manage.py runserver

    Traceback (most recent call last):

    File "manage.py", line 24, in

    execute_from_command_line(sys.argv)

    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line

    utility.execute()

    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 355, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv

    self.execute(*args, **cmd_options)

    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 63, in execute

    super(Command, self).execute(*args, **options)

    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 330, in execute

    output = self.handle(*args, **options)

    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 102, in handle

    self.run(**options)

    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 111, in run

    autoreload.main(self.inner_run, None, options)

    File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 341, in main

    reloader(wrapped_main_func, args, kwargs)

    File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 312, in python_reloader

    exit_code = restart_with_reloader()

    File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 294, in restart_with_reloader str_value = force_bytes(new_environ[key], encoding=encoding)

    File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 124, inforce_bytes return s.decode('utf-8', errors).encode(encoding, errors)

    File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode

    return codecs.utf_8_decode(input, errors, True)

    UnicodeDecodeError: 'utf8' codec can't decode byte 0xca in position 367: invalid continuation byte

    解决的办法:

    原本这一行的代码是:

    str_value = force_bytes(new_environ[key], encoding=encoding)

    将其修改为:

    str_value = force_bytes(new_environ[key], encoding=‘utf-8’)

    保存这个文件。然后重新在cmd的界面里面执行python manage.py runserver就可以执行成功了。

    相关文章

      网友评论

          本文标题:Django框架manage.py runserver 编码问题

          本文链接:https://www.haomeiwen.com/subject/ibwldxtx.html