本文介绍了'ascii'编解码器不能解码字节(使用django时的问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python写了一个简单的html解析类,它似乎工作正常,然后我尝试使用它与django,我得到这个错误:

I wrote a simple html parsing class in python and it seems to work fine and then I try to use it with django and I get this error:

'ascii' codec can't decode byte 0xc2 in position 54465: ordinal not in range(128)

这是奇怪的,因为我添加了这个:#encoding:utf-8 到我的类的顶部。我真的不知道编码,但有人可能会给我一个想法,这里是什么? Btw,我也保证源html已经在utf-8。谢谢!

which is strange because I added this: # encoding: utf-8 to the top of my class. I don't really know much about encoding but can someone perhaps give me an idea of what's going here? Btw, I also insured that the source html was already in utf-8. Thanks!

推荐答案

好的,我得到了。所有我需要做的是在django视图中包括# - * - coding:utf-8 - * - ,并解决了!

okay, I got it. All I needed to do was include # -*- coding: utf-8 -*- in the django view as well and that solved it!

这篇关于'ascii'编解码器不能解码字节(使用django时的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:32