开发者

Django File Upload: How do I handle the file?

开发者 https://www.devze.com 2022-12-15 07:35 出处:网络
I have read the documentation several times, but I am still confused. When you specify a model in Django, you can specify the file\'s destination. However, in the documentation, they go on a great dea

I have read the documentation several times, but I am still confused. When you specify a model in Django, you can specify the file's destination. However, in the documentation, they go on a great deal about handling the write to disk manually. My question is: Is it better to just say form开发者_高级运维.save() or to write a file handler with a hardcoded(?) path. form.save() has been flakey for me.


Calling the form's save method should work just fine, assuming you are using a forms.ModelForm subclass. Some things to note.

  • Make sure to properly set the form's enctype in the template
  • Be sure the view that handles the form checks for files

    form=MyModelForm(data=request.POST, files=request.FILES)

When you say form.save() has been flaky, what do you mean?

0

精彩评论

暂无评论...
验证码 换一张
取 消