【发布时间】: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