0

I am trying to use Dropzone with Django, but I get a MultiValueDictKeyError.

This is my html form:

<form action="{% url 'AlbumsManagerApp:album_add_photo' album_pk=album.id %}" class="dropzone" method="POST">
{% csrf_token %}
   <div class="nav nav-bar">
      <input type="submit" name="submit-accept" value="Aceptar" class="btn btn-success">
      <input type="submit" name="submit-cancel" value="Cancelar" class="btn btn-danger">
    </div>
</form>

This is my view:

class AlbumAddPhotoView(LoginRequiredMixin, View):

    def get(self, request, album_pk):
        album = Album.objects.get(id=album_pk)
        context={'album': album }

        return render(request, 'AlbumsManagerApp/form_upload.html', context)

    def post(self, request, album_pk):
        if 'submit-accept' in request.POST:
            files = request.FILES['file']
            print(files)

        return redirect('AlbumsManagerApp:albums', album_pk=album_pk)

I followed the answer to the question Trying to use django and dropzone/, but I still get the same error.

HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93
  • You are missing the `enctype="multipart/form-data"` on your form, so no files will get sent to the view. – solarissmoke Apr 14 '18 at 04:13
  • Thanks a lot, but I have found that it works without it by removing the `method="POST"`, but now the `return redirect('AlbumsManagerApp:albums', album_pk=album_pk)` is not working properly. – HuLu ViCa Apr 14 '18 at 20:13
  • I fixed the latest problem by using `return HttpResponseRedirect(reverse('AlbumsManagerApp:albums', args=(album_pk,)))` , and I also added whats is recommended at https://amatellanes.wordpress.com/2013/11/05/dropzonejs-django-how-to-build-a-file-upload-form/, but I still get the same original error. – HuLu ViCa Apr 14 '18 at 23:06
  • I used the answer to https://stackoverflow.com/questions/45363984/multivaluedictkeyerror-when-using-dropzonejs-with-django, and the error disappeared, but I get no files. – HuLu ViCa Apr 15 '18 at 01:24

0 Answers0