Django打开测试网页时报错: 'utf-8' codec can't decode…… invalid start byte

所有项目文件和路径都无中文,计算机名为英文。
pyhon版本3.7.6, Django版本2.1
求问这种问题该怎么解决?

Django打开测试网页时报错: 'utf-8' codec can't decode…… invalid start byte
Django打开测试网页时报错: 'utf-8' codec can't decode…… invalid start byte

Traceback完整内容:

Environment:

Request Method: GET

Request URL: http://127.0.0.1:8000/

Django Version: 2.1

Python Version: 3.7.6

Installed Applications:

['pages.apps.PagesConfig',

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles']

Installed Middleware:

['django.middleware.security.SecurityMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.middleware.common.CommonMiddleware',

'django.middleware.csrf.CsrfViewMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.contrib.messages.middleware.MessageMiddleware',

'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\core\handlers\exception.py" in inner

34. response = get_response(request)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\core\handlers\base.py" in _get_response

156. response = self.process_exception_by_middleware(e, request)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\core\handlers\base.py" in _get_response

154. response = response.render()

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\response.py" in render

106. self.content = self.rendered_content

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\response.py" in rendered_content

81. template = self.resolve_template(self.template_name)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\response.py" in resolve_template

63. return select_template(template, using=self.using)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\loader.py" in select_template

42. return engine.get_template(template_name)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\backends\django.py" in get_template

34. return Template(self.engine.get_template(template_name), self)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\engine.py" in get_template

144. template, origin = self.find_template(template_name)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\engine.py" in find_template

126. template = loader.get_template(name, skip=skip)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\loaders\base.py" in get_template

24. contents = self.get_contents(origin)

File "C:\Users\13308\.virtualenvs\pages-tyRMmbey\lib\site-packages\django\template\loaders\filesystem.py" in get_contents

24. return fp.read()

File "c:\users\13308\appdata\local\programs\python\python37\lib\codecs.py" in decode

322. (result, consumed) = self._buffer_decode(data, self.errors, final)

Exception Type: UnicodeDecodeError at /

Exception Value: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte


回答:

是你的html里面有不能解析的字符,到html文档里修改 utf-8 改成gbk 就好了
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

以上是 Django打开测试网页时报错: &#x27;utf-8&#x27; codec can&#x27;t decode…… invalid start byte 的全部内容, 来源链接: utcz.com/p/937807.html

回到顶部