【问题标题】:in __init__ raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg)) [closed]在 __init__ raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg)) [关闭]
【发布时间】:2019-12-10 02:02:17
【问题描述】:
board = Board(name='Django', description='This is a board about Django.')    

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/babak/myproject/venv/lib/python3.6/site-packages/django/db/models/base.py", line 501, in __init__
    raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg))
TypeError: Board() got an unexpected keyword argument 'description'

【问题讨论】:

  • 您没有向我们展示Board 是什么,但它的__init__ 方法不接受description 参数
  • 我想尝试在终端 simpleisbetterthancomplex.com/series/2017/09/11/… 中构建模态 api
  • 我的答案仍然有效...您对Board.__init__ 的实现不接受description 参数。
  • 需要显示Board的定义

标签: python django


【解决方案1】:

您的函数 Board 似乎无法将 description 识别为参数。 这意味着,您的函数不接受相应的参数。

最好去掉description参数。

【讨论】:

  • 1.很明显,Board 是一个类,而不是一个函数(准确地说是一个 Django 模型)。 2. description 应该添加__init__,而不是从对Board的调用中删除
  • 你可能是对的。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-03-29
  • 2021-01-19
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 1970-01-01
  • 2021-06-11
  • 1970-01-01
相关资源
最近更新 更多