Django File Upload but request.FILES empty?

  • Posted on: 25 September 2016
  • By: oon
Django File Upload

This is simple but annoying error, when you setting up Django form with File Upload, after you successfully upload the file, but when you check the request.FILES was empty.

What happened?

One of the answer is you probably forget to set encoding type of your form

<form action="" method="post" enctype="multipart/form-data">{% csrf_token %}
{{ form.as_p }}
<button type="submit">{% trans 'Submit' %}</button>
</form>

source [1]

[1]https://stackoverflow.com/a/5567063/3991504

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.