为什么 models.py 中需要一个 unicode 函数?
即
def __unicode__(self)
return sumid;
最佳答案
不是。如果您定义了一个 __unicode__()
方法,当 Django 需要在需要字符串表示的上下文中呈现对象时(例如,在模型的管理页面中),它将调用它。
The
__unicode__()
method is called whenever you callunicode()
on an object. Since Django's database backends will return Unicode strings in your model's attributes, you would normally want to write a__unicode__()
method for your model.
关于python - Django中unicode的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1818224/