[Fixed]-What am I not doing right in this django file upload form?

32👍

    form = UploadFileForm(request.POST, request.FILES)

43👍

Just for future reference. I had the same error, though I included request.FILES in form initialization. The problem was in the template: I forgot to add enctype="multipart/form-data" attribute to the <form> tag.

0👍

If you have included request.FILES and added the enctype="multipart/form-data", but are still seeing this error, it could be you are not declaring the <input> correctly.

For example, if explicitly declare the input html in your template like:

<input type="file" value="Upload CSV File" />

You may not be passing the expected input id or name attributes of the input form element.

Be sure that your template is using the form element tag, i.e. {{ form.file }},
which django will then render as: <input id="id_file" name="file" type="file" required=""> on the page.

👤Rob

Leave a comment