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

后端 未结 2 1580
暗喜
暗喜 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 03:14

    You can not pass initial data to a file field. The 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)

提交回复
热议问题