0

我目前正在使用嵌套表单集,并且在浏览 Django 源代码时,我发现我对 request.POST 数据中新创建的表单数据如何传播到新表单对象没有任何更基本的了解。

问题:

当新的表单数据被注入 request.POST(例如通过 javascript)时,它如何被解析并填充到一个新的 Django Form 对象中?

4

1 回答 1

0

Django use the terminology Bound Form for a form with data and Unbound Form for a form that hasnt got any data yet.

A form goes over the cleaning steps to get its data, it will get the QueryDict with the GET/POST values, then just loop over them and run any specific clean methods on the data.

Its quite easy to understand the code if you want to read it yourself

https://github.com/django/django/blob/master/django/forms/forms.py

You cannot add data with javascript, javascript is client side only. you can POST up data from javascript to the server, but the server does not care what posts the data.

于 2013-07-28T05:37:50.237 回答