Django Imagefield not working properly via ModelForm

后端 未结 1 706
一生所求
一生所求 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 <form> tag should look something like this:

    <form enctype="multipart/form-data" method="post" action="">
    
    0 讨论(0)
提交回复
热议问题