Django Imagefield not working properly via ModelForm

后端 未结 1 711
一生所求
一生所求 2021-01-30 07:00

I\'m certain I\'m doing something really obviously stupid, but I\'ve been trying to figure it out for a few hours now and nothing is jumping out at me.

I\'m using a Mode

1条回答
  •  攒了一身酷
    2021-01-30 07:19

    Well I feel like an idiot. In order for Django to be able to process uploaded files, you need to pass the request.FILES variable to the form (makes sense, right?!)

    In my case the following line goes from:

    f = AdminEditForm(request.POST, instance = company)
    

    To:

    f = AdminEditForm(request.POST, request.FILES, instance = company)
    

    Another thing to check (if you run into something like this in the future) is that your form is multipart. Your

    tag should look something like this:

    
    

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