'Django enctype="multipart/form-data" not setting POST data
I need to send both a file and some data from input texts.
This is the form I'm working on:
<form method="post" action="{% url catalog_create_ajax_upload %}" enctype="multipart/form-data" id="create-form">
<input type="text" id="new-catalog-name" name="catalog_name" class="large-input" placeholder="catalog title" />
<div id="new-catalog">
<input type="file" name="file">
</div>
</form>
When sent, I excpect request.POST['catalog_name']to have a value, but the whole POST attribute in an empty dictionary.
Any help?
Solution 1:[1]
Make sure your view function should post image file like this
def index(request):
image = 'file' in request.FILES and request.FILES['file']
Use request.FILES instead of request.POST
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aashish Kumar |
