zoukankan      html  css  js  c++  java
  • TypeError at /admin/booktest/book_infor/add/ __str__ returned non-string (type bytes)

    问题:

    在Django的管理页面进行添加的时候

    出现了如下的错误

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

     原因就在于你在写的models模块的时候没有注意你使用的是python2还是python3系列,两者实际上有着非常大的区别。就好像成人和小孩的区别一样

    pyhotn2中的__str__():方法

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

    python3中的__str__():方法

        def __str__(self):
            return self.btitle

    因为在python3中会自动进行编码不需要指定编码格式,所以在python3中使用python2的那种格式就会报错

    本文来自博客园,作者:江湖混子,转载请注明原文链接:https://www.cnblogs.com/huao990928/p/11829543.html

  • 相关阅读:
    文件
    drf序列化组件
    drf入门规范
    单例模式
    初识drf
    restful规范
    虚拟环境使用
    vue基础(三)
    vue基础(二)
    作业
  • 原文地址:https://www.cnblogs.com/huao990928/p/11829543.html
Copyright © 2011-2022 走看看