Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';型号';对象没有属性';更换';_Python_Django - Fatal编程技术网

Python ';型号';对象没有属性';更换';

Python ';型号';对象没有属性';更换';,python,django,Python,Django,我正在Django 1.6应用程序中使用自定义用户模型TrackUser。当我想删除Adminpanel中的用户时,我会遇到以下错误: “TrackUser”对象没有属性“replace” 我已经看过了,尽管我们的回溯都在。/django/utils/html.py上结束,但我没有找到解决问题的方法 型号 class TrackUser(AbstractBaseUser, PermissionsMixin): #User data email = models.EmailFiel

我正在Django 1.6应用程序中使用自定义用户模型
TrackUser
。当我想删除Adminpanel中的用户时,我会遇到以下错误:

“TrackUser”对象没有属性“replace”

我已经看过了,尽管我们的回溯都在
。/django/utils/html.py上结束,但我没有找到解决问题的方法

型号

class TrackUser(AbstractBaseUser, PermissionsMixin):
    #User data
    email = models.EmailField(unique=True)
    first_name = models.CharField(max_length=75)
    last_name = models.CharField(max_length=75)
    tel_number = models.BigIntegerField(blank=True, null=True)
    address = models.TextField(blank=True, null=True)

    #User options
    #True for first_name last_name
    #False for last_name first_name
    full_name_order = models.BooleanField(blank=True, default=True)

    #Django necessities
    date_joined = models.DateTimeField(default=timezone.now)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)

    #Sales fields
    percentage_of_sales = models.IntegerField(default=0)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name']
    objects = UserManager()

    def get_absolute_url(self):
        return reverse('user_detail', args=[self.pk])

    def get_full_name(self):
        if self.full_name_order:
            order = (self.first_name, self.last_name)
        else:
            order = (self.last_name, self.first_name)
        return "%s %s" % order

    def get_short_name(self):
        return self.first_name

    def __unicode__(self):
        return self.get_full_name()
回溯

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/users/trackuser/18/delete/

Django Version: 1.6.5
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'clients',
 'contracts',
 'projects',
 'products',
 'users',
 'project_settings',
 'south')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  432.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/db/transaction.py" in inner
  371.                 return func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/options.py" in delete_view
  1457.             [obj], opts, request.user, self.admin_site, using)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in get_deleted_objects
  137.     to_delete = collector.nested(format_callback)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in nested
  191.             roots.extend(self._nested(root, seen, format_callback))
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in _nested
  174.             children.extend(self._nested(child, seen, format_callback))
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in _nested
  176.             ret = [format_callback(obj)]
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in format_callback
  130.                                obj)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in format_html
  79.     args_safe = map(conditional_escape, args)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in conditional_escape
  71.         return escape(text)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
  203.             return func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in escape
  39.     return mark_safe(force_text(text).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;'))

Exception Type: AttributeError at /admin/users/trackuser/18/delete/
Exception Value: 'TrackUser' object has no attribute 'replace'
环境:
请求方法:获取
请求URL:http://127.0.0.1:8000/admin/users/trackuser/18/delete/
Django版本:1.6.5
Python版本:2.7.6
已安装的应用程序:
(“django.contrib.admin”,
“django.contrib.auth”,
“django.contrib.contenttypes”,
“django.contrib.sessions”,
“django.contrib.messages”,
“django.contrib.staticfiles”,
“客户”,
"合约",,
“项目”,
"产品",,
“用户”,
“项目设置”,
"南")
已安装的中间件:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
“django.middleware.csrf.CsrfViewMiddleware”,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.xframeoptions中间件')
回溯:
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/core/handlers/base.py”,在get_响应中
112响应=包装的回调(请求,*回调参数,**回调参数)
包装器中的文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/options.py”
432返回self.admin\u site.admin\u视图(视图)(*args,**kwargs)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/decorators.py”位于
99响应=查看功能(请求,*args,**kwargs)
文件“/Users/jgyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/views/decorators/cache.py”位于
52响应=查看功能(请求,*args,**kwargs)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/sites.py”,位于内部
198返回视图(请求、*args、**kwargs)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py”位于
29返回边界函数(*args,**kwargs)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/decorators.py”位于
99响应=查看功能(请求,*args,**kwargs)
绑定函数中的文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/decorators.py”
25返回函数(self,*args2,**kwargs2)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/db/transaction.py”,位于内部
371返回函数(*args,**kwargs)
删除视图中的文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/options.py”
1457[obj],选项,request.user,self.admin\u站点,使用)
文件“/Users/jgyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/util.py”,在get_deleted_objects中
137to_delete=collector.nested(格式化_回调)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py”,嵌套
191extend(self.\u嵌套(root,seen,格式化\u回调))
文件“/Users/jgyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/util.py”位于
174extend(self.\u嵌套(child,seen,格式化\u回调))
文件“/Users/jgyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/util.py”位于
176ret=[格式\回调(obj)]
文件“/Users/jgyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/contrib/admin/util.py”,格式为
130(obj)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/html.py”,格式为
79args\u safe=map(条件转义,args)
文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/html.py”,在条件转义中
71返回转义(文本)
包装器中的文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/functional.py”
203返回函数(*args,**kwargs)
escape中的文件“/Users/jghylebert/Documents/projects/nuntra/trackapp/lib/python2.7/site packages/django/utils/html.py”
39返回标记“安全”(强制文本。替换(“&”、“&;”)。替换(“,”)。替换(“,”)。替换(“,”)。替换(“,”)(“,”,”)。替换(“,”&';))
异常类型:AttributeError at/admin/users/trackuser/18/delete/
异常值:“TrackUser”对象没有属性“replace”

显然,问题只在
TrackUser
链接到另一个模型时出现

在其中的一个模型中,我将

def __unicode__(self):
    return self.user


这解决了问题

我唯一能想到的是,如果
名字
姓氏
为空,但您没有
null
子句。这两个都是填充的。我甚至尝试更改
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。但是,同样的错误依然存在
def __unicode__(self):
    return self.user.get_full_name()