Python中文
首页
教程
问答
标签
搜索
登录
注册
“getattr():对于带有ImageField的模型,管理面板中的属性名必须为string”错误
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我设置了以下模型:</p> <pre><code>class UserProfile(models.Model): "Additional attributes for users." url = models.URLField() location = models.CharField(max_length=100) user = models.ForeignKey(User, unique=True) avatar = models.ImageField(upload_to='/home/something/www/avatars', height_field=80, width_field=80) def __unicode__(self): return "Profile of " + self.user.username </code></pre> <p>它应该存储有关用户的附加信息,例如<strong>化身</strong>。</p> <p>不幸的是,当我试图通过管理面板上传图像时,它会给我一个错误,比如:</p> <pre><code>getattr(): attribute name must be string </code></pre> <p>当我从模型中删除该字段时,不会生成该字段,请执行db reset并重新加载服务器。我想原因是这个特殊的领域,只是不知道如何。</p> <p>这是我的回溯:</p> <pre><code>File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in wrapper 226. return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/lib/pymodules/python2.6/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/usr/lib/pymodules/python2.6/django/contrib/admin/sites.py" in inner 186. return view(request, *args, **kwargs) File "/usr/lib/pymodules/python2.6/django/db/transaction.py" in _commit_on_success 240. res = func(*args, **kw) File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in add_view 718. new_object = self.save_form(request, form, change=False) File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in save_form 551. return form.save(commit=False) File "/usr/lib/pymodules/python2.6/django/forms/models.py" in save 407. fail_message, commit, exclude=self._meta.exclude) File "/usr/lib/pymodules/python2.6/django/forms/models.py" in save_instance 65. f.save_form_data(instance, cleaned_data[f.name]) File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in save_form_data 283. setattr(instance, self.name, data) File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in __set__ 316. self.field.update_dimension_fields(instance, force=True) File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in update_dimension_fields 368. (self.width_field and not getattr(instance, self.width_field)) Exception Type: TypeError at /admin/proj/userprofile/add/ Exception Value: getattr(): attribute name must be string </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>问题可能是:</p> <pre><code>height_field=80, width_field=80 </code></pre> <p>如果使用<code>height_field</code>和<code>width_field</code>,则应该是模型上包含高度和宽度信息的字段的名称。把这个修好它应该能用。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
7 回答
python中两个字符串上的异或操作数?
7 回答
Python中两个字符串中的类似句子
6 回答
Python中两个字符串之间的Hamming距离
3 回答
python中两个字符串之间的匹配模式
1 回答
python中两个字符串之间的按位或
7 回答
python中两个字符串之间的数据(字节)切片
5 回答
python中两个字符串之间的模式
3 回答
python中两个字符串作为子字符串的区别
5 回答
Python中两个字符串元组的比较
1 回答
Python中两个字符串列表中的公共字符串
2 回答
python中两个字符串的Anagram测试
3 回答
Python中两个字符串的正则匹配
7 回答
python中两个字符串的笛卡尔乘积
6 回答
Python中两个字符串相似性的比较
4 回答
python中两个字符串语义相似度的求法
8 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
4 回答
Python中两个对数方程之间的插值和平滑数据
1 回答
Python中两个对象之间的And/Or运算符
2 回答
python中两个嵌套字典中相似键的和值
2 回答