管理页面显示django中的错误

时间:2017-09-16 16:10:31

标签: python django

/ 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"

1 个答案:

答案 0 :(得分:1)

__unicode__需要返回字符串。

变化:

def __unicode__(self):
    return self.uid,self.uname

def __unicode__(self):
    return u"{} {}".format(self.uid, self.uname)