how to pass initial value of FileField to Formset (in Django)

后端 未结 2 1577
暗喜
暗喜 2021-01-17 02:46

I am trying to populate a Django formset using data from a POST/FILE request. I am able to populate all the fields except the FileField. It seems that initial c

相关标签:
2条回答
  • 2021-01-17 02:52

    You can not pass any initial values when you are working with file uploads.

    0 讨论(0)
  • 2021-01-17 03:14

    You can not pass initial data to a file field. The <input type="file" /> will always be blank when the browser renders it.

    To pass request.FILES to a formset, just specify it as the second argument after POST.

    http://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-a-formset-in-views-and-templates

    FormSet(request.POST, request.FILES)

    0 讨论(0)
提交回复
热议问题