Difference between Django Form 'initial' and 'bound data'?

后端 未结 3 377
情话喂你
情话喂你 2020-12-08 08:05

Given an example like this:

class MyForm(forms.Form): 
    name = forms.CharField()

I\'m trying to grasp what the difference between the fo

3条回答
  •  情话喂你
    2020-12-08 08:47

    Another difference is that data expects something that widgets can parse whereas initial is per-field. This makes a difference if you e.g. use MultiWidgets. In such case data should contain something like

    {'myfield_0': 'data for subwidget 0', 
     'myfield_1': 'data for subwidget 1'}
    

    whereas initial expects something like this:

    {'myfield': 'data for subwidget 0,data for subwidget 1'}
    

提交回复
热议问题