在 Django TestClient 中使用默认值发回表单
我正在 Django 中为某些表单编写一些测试。这些表单经常更改,因此我试图避免将表单参数硬编码到我的测试中,因为每次我的表单更改时,我也必须修改测试。我有很多这种性质的形式。我主要测试信息是否正确存储在正确的表中,而不必真正关心每个表单字段。
使用 Django TestClient,有没有一种方法可以获取包含表单的页面,然后使用提交的默认表单字段值将其发回?
我已经用谷歌搜索过这个但没有结果。
大家有帮助吗?谢谢。
I'm writing some tests for some forms in Django. These forms change quite often so I'm trying to avoid hard-coding the form parameters into my tests as because every time my form would change, I'd have to modify the tests as well. I have quite a few forms of this nature. I'm mainly testing that the information is stored properly in the correct tables without really bothering about each form field.
Using the Django TestClient, is there a way I could fetch the page with the form and then post it back with the default form field values filed in?
I've Googled around for this but to no avail.
An y help guys? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前不得不做这样的事情,不幸的是没有简单的方法可以做到这一点。我能想到的最好办法是渲染表单,然后使用 BeautifulSoup 解析结果以获取输入和选择的所有值。像这样的东西:
I've had to do something like this before, and unfortunately there is no easy way to do it. The best I could come up with was to render the form, then parse the result with BeautifulSoup to get all the values of the inputs and selects. Something like: