/ admin / student / user /中的TypeError 强制转换为Unicode:需要字符串或缓冲区,找到元组
知道它是什么意思吗?
admin.py
from django.contrib import admin
from .models import user
class userAdmin(admin.ModelAdmin):
fieldsets=[
(None,{'fields':['uid']}),
(None,{'fields':['uname']}),
(None,{'fields':['email']}),
(None,{'fields':['password']}),
]
admin.site.register(user,userAdmin)
models.py
class user(models.Model):
uid=models.IntegerField(unique=True,default=0)
uname=models.CharField(max_length=50)
email=models.EmailField()
password=models.CharField(max_length=20)
def __unicode__(self):
return self.uid,self.uname
class Meta:
db_table="user"
答案 0 :(得分:1)
__unicode__
需要返回字符串。
变化:
def __unicode__(self):
return self.uid,self.uname
到
def __unicode__(self):
return u"{} {}".format(self.uid, self.uname)