5

File Uploads Using Django FormView | Snakey Code

 2 years ago
source link: https://snakeycode.wordpress.com/2021/01/17/file-uploads-using-django-formview/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

File Uploads Using Django FormView

As of Django 3.1, the documentation did not show how to upload files with the Django class based view; FormView. To accomplish this, go to the Django documentation on file uploads.

The trick is to realize that the variable, request.FILES[‘file’] in the post method of the view, is the same as the variable, self.files[‘MY FIELD NAME’] in forms.Form class. In my case, I needed this in the form to do validation.

Advertisements
Report this ad

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK