/ admin / auth / user /中的TypeError

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了/ admin / auth / user /中的TypeError相关的知识,希望对你有一定的参考价值。

当我尝试从管理面板中删除用户时出现这样的错误

/ admin / auth / user /'bool'对象的TypeError不可调用

models.朋友

class PROFILE(models.Model):
kullanıcı = models.OneToOneField(User,on_delete=True)
birthday = models.DateField(verbose_name="Birthday",
                            blank=False,null=False)
gender   = models.CharField(max_length=15, blank=False,null=
                            False,choices=gender)
language = models.CharField(max_length=20, blank=False,null=False,
                            verbose_name="language",choices=languages)


def set_token(self):

    self.token = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789') 
                                for i in range(15)])

def save(self, *args, **kwargs):
    super(PROFILE, self).save(*args, **kwargs)
    self.set_token()

class Meta:

    verbose_name_plural = 'PROFILE'
    ordering= ["id"]

def __str__(self):
    return "{}".format(self.kullanıcı.username)



class Q(models.Model):
   author  = models.ForeignKey(User, on_delete=models.CASCADE)
   ... class Meta, __str__ ....

首先'kullanıcı'是'用户',但我改变了因为django冲突的可能性。但我仍有这个问题

/ admin / auth / user /'bool'对象的TypeError不可调用请求方法:POST请求URL:http://192.168.1.34:8000/admin/auth/user/ Django版本:2.1异常类型:TypeError异常值: 'bool'对象不可调用异常位置:/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.pyin collect,第221行Python可执行文件:/ home / mete /Masaüstü/ ask / venv / bin / python Python版本:3.6.5 Python路径: ['/ home / mete /Masaüstü/ ask / ask','/ usr / lib / python36.zip','/ usr / lib / python3.6','/ usr / lib / python3.6 / lib-dadload' ,'/ home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages']服务器时间:Cum,31Ağu2016816:35:51 +0000

>

回溯:内部34中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/exception.py”response = get_response(request)File“/ home / mete /Masaüstü/ ask / venv / lib / python3.6 / site-packages / django / core / handlers / base.py“in _get_response 126. response = self.process_exception_by_middleware(e,request)File”/ home / mete /Masaüstü /ask/venv/lib/python3.6/site-packages/django/core/handlers/base.py“在_get_response 124. response = wrapped_callback(request,* callback_args,** callback_kwargs)File”/ home / mete /Masaüstü / wrap/venv/lib/python3.6/site-packages/django/contrib/admin/options.py“在包装器607中。返回self.admin_site.admin_view(查看)(* args,** kwargs)文件”/ home /mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py“in _wrapped_view 142. response = view_func(request,* args,** kwargs)File”/ home / mete在_wrapped_view_func中的/Masaüstü/ask/venv/lib/python3.6/site-packages/django/views/decorators/cache.py“44。response = view_fun c(request,* args,** kwargs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/sites.py”在内部223.返回视图(请求,* args,** kwargs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py”在_wrapper 45.中返回bound_method(* args) ,** kwargs)在_wrapped_view 142中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py”.response = view_func(request,* args,* * kwargs)在changelist_view 1711中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”.response = self.response_action(request,queryset = cl.get_queryset(request))在response_action 1411中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”.response = func(self,请求,queryset)delete_selected中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/actions.py”28. deletable_objects,model_count, perms_needed,protected = modeladmin.get_deleted_objects(queryset,request)> get_deleted_objects 1833中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”。 return get_deleted_objects(objs,request,self.admin_site)get_deleted_objects 134中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py”。收集器。收集(objs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py”收集197. return super()。collect(objs, source_attr = source_attr,** kwargs)收集221中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.py”field.remote_field.on_delete (self,field,sub_objs,self.using)

异常类型:/ admin / auth / user / Exception中的TypeError值:'bool'对象不可调用

答案

问题出在on_delete模型的Profile论证中。 on_delete参数不应该是布尔值。 on_delete的可能值可以在这里找到,Related Field- on_delete。 所以,改变你的PROFILE

class PROFILE(models.Model):
    kullanıcı = models.OneToOneField(User,on_delete=models.CASCADE)
    .... other fields

以上是关于/ admin / auth / user /中的TypeError的主要内容,如果未能解决你的问题,请参考以下文章

firebase:admin.auth().updateUser() 导致 auth/user-token-expired

/admin/login/ 的 OperationalError 没有这样的表:auth_user

Django框架之admin管理后台

Django---启动admin的报no such table: auth_user错误

Django admin 修改密码

使用列表推导创建指定的词典列表