【问题标题】:Django: Passing 'name' to Client.post()Django:将“名称”传递给 Client.post()
【发布时间】:2021-01-14 07:18:06
【问题描述】:

我想在 Django 的测试中将“name”变量从客户端传递给 request.POST.get(),以便在视图中由 post 函数进一步处理。

类似的东西(产品是 ChoiceField 形式):

response = c.post('/ordersys/orders/create/', {'product':product, 'amount':3}, name="Add")

我希望从客户发帖时是否为真:

if request.POST.get("Add"):
   self.add_to_order(product, amount)

在表单中,提交这样的作品:

<input type="submit" name="Add" value="Add item to order">

【问题讨论】:

  • 只需在 post 参数中传递您选择的一些值,例如:{'product':product, 'amount':3, 'name': True}

标签: python django forms unit-testing testing


【解决方案1】:

感谢 Abdul Aziz Barkat 在我的帖子下发表评论,我才得以成功。我只需要添加 'Add':True 就我而言。

【讨论】:

    猜你喜欢
    • 2014-07-03
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    相关资源
    最近更新 更多