Django python_2_unicode_compatible装饰器兼容pyton2.x

时间:2019-03-27 16:47:10   收藏:0   阅读:2592
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible # 当你想支持python2版本的时候才需要这个装饰器
class Question(models.Model):
    # ...
    def __str__(self):   # 在python2版本中使用的是__unicode__
        return self.question_text

@python_2_unicode_compatible 
class Choice(models.Model):
    # ...
    def __str__(self):
        return self.choice_text

 

原文:https://www.cnblogs.com/icemonkey/p/10608206.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!