Django报错 query = query.decode(errors=‘replace‘)AttributeError: ‘str‘ object has no attribute ‘decod

specific error

Since you are using Python 3.x version and trying to use Python 2.x version method. In Python 2.x, str the type is a byte string, so  decode it can be converted to a Unicode string using the method. However, in Python 3.x, str the type defaults to a Unicode string, so there is no longer  decode a method.

This error usually occurs when using Python 3.x and Django 1.x and when using a MySQL database. The reason is that when the code written by python2.x is run in Python 3.x, the string inside is of Unicode type and no longer has a decode method.

The online solution is to open the corresponding file and change the decode of line 146 to encode

But I can't modify this file, so I can try the following method

Modify the code to this

 

 

 

Guess you like

Origin blog.csdn.net/qq_52351946/article/details/131263867