Django框架manage.py runserver 編碼問(wèn)題

#換了電腦重裝了環(huán)境,發(fā)現(xiàn)Django的項(xiàng)目起不來(lái),折騰了好久,才看到網(wǎng)上一帖子,做下記錄。

報(bào)錯(cuò)大概如下:

#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’)

保存這個(gè)文件。然后重新在cmd的界面里面執(zhí)行python manage.py runserver就可以執(zhí)行成功了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容