我已经定义了UserDetail模型,它与User有一对一的关系。
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from xlwings import Workbook, Sheet, Range, Chart
>>> wb = Workbook()
>>> Sheet(1).name
u'Sheet1'
>>> Range('A1').value = 'Foo 1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/xlwings/main.py", line 622, in __init__
self.row2 = self.row1 + xlplatform.count_rows(self.xl_sheet, range_address) - 1
File "/Library/Python/2.7/site-packages/xlwings/_xlmac.py", line 145, in count_rows
return xl_sheet.cells[range_address].count(each=kw.row)
File "/Library/Python/2.7/site-packages/aeosa/appscript/reference.py", line 431, in __call__
raise TypeError('Unknown keyword argument %r.' % name)
TypeError: Unknown keyword argument 'each'.
>>>
但是当我在我的视图中通过request.user尝试访问UserDetail对象时,它会引发错误,因为“用户没有用户详细信息。”。
class UserDetail(models.Model):
user = models.OneToOneField(User)
....
虽然我能够在Django shell中使用 user.userdetail 。 我不知道它为什么会发生,请求.user与User对象有什么不同吗?
答案 0 :(得分:3)
没有。这是因为该特定用户没有关联的UserDetail实例。