TypeError at /admin/booktest/book_infor/add/ __str__ returned non-string (type bytes)

problem:

When Django's admin page to add

 

 

The following error occurred

 TypeError at /admin/booktest/book_infor/add/ __str__ returned non-string (type bytes)

 

 The reason is that you are writing a module models did not pay attention when you are using the python2 or python3 series, both in fact has a very big difference. If the difference between adults and children as

pyhotn2 in __str __ (): Method

1     def __str__(self):
2         return self.btitle.encode('utf-8')

python3 in __str __ (): Method

    def __str__(self):
        return self.btitle

Because encoded automatically in python3 not necessary to specify the encoding formats, the use python2 in that the format will be given python3

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/huao990928/p/11829543.html