Accessing form fields as properties in a django view

后端 未结 4 631
时光说笑
时光说笑 2020-12-29 09:01

According to the Django tutorial, you should access form fields using cleaned_data dictionary. I\'m wondering why I can\'t access the properties of the form directly? My for

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 09:52

    If your form is validated then you can access myForm cleaned_data:

    print myForm.cleaned_data.get('description')
    

    If you want to see why you cannot access myForm.description then you can see the data dictionary of your myForm:

    print myForm.__dict__
    

提交回复
热议问题