javascript - MultiValueDictKeyError when using DropzoneJS with Django -


i'm making profile picture feature website, started using dropzonejs i'm having issue submitting file. picture drop zone fine, appears "x" on it, , when hover on picture can see multivaluedictkeyerror error. same error when click submit button without selecting file. assume issue file isn't being submitted button? how do that?

html/js:

<script type='text/javascript'>  dropzone.options.mydropzone = {      init : function() {         var submitbutton = document.queryselector("#submitbtn")         mydropzone = this;         submitbutton.addeventlistener("click", function() {             mydropzone.processqueue();         });         this.on("addedfile", function() {             document.getelementbyid('submitbtn').style.visibility = "visible";         });          this.on('addedfile', function(){             if (this.files[1]!=null){                 this.removefile(this.files[0]);             }         });       } };  dropzone.options.myawesomedropzone = {   accept: function(file, done) {     console.log("uploaded");    },   init: function() {     this.on("addedfile", function() {       if (this.files[1]!=null){         this.removefile(this.files[0]);         //document.getelementbyid('submitbtn').style.visibility = "visible";       }     });   }   }; </script> <!-- modal --> <div id="picmodal" class="modal">    <!-- modal content -->   <div class="modal-content">     <span class="close"></span>     <form action="{% url 'profile_test' %}" method='post' enctype="multipart/form-data" class="dropzone" id="my-dropzone">{% csrf_token %}         <button id='submitbtn' type='submit' style='visibility: hidden;'> submit </button>         <input id='submit-all' type='file' name='uploaded_image'/>             {{form}}     </form>   </div>  </div>  </body> 

here's screenshot of error

edit

i added autoprocessqueue: false, mydropzone. i'm not getting issue when hover on picture anymore. instead when press submit takes me multivaluedictkeyerror error page

*edit 2**

views.py  def profile_test(request):     #going use view display profile page, , test alterations     form = imageuploadform(request.post, request.files)     user = user.objects.get(id=request.user.id)     if request.method == "post":          print 'valid'         user.userprofile.img = request.post.get('uploaded_image', false)         user.userprofile.save()         return httpresponseredirect(reverse("profile_test"))     else:         print 'invalid'         form = imageuploadform()      return render(request, 'profile_test.html', {form:'form', user: 'user'}) 

i used have user.userprofile.img = request.files["uploaded_image"] changed it, seemed maek things better. image drop zone, , when hover on won't see error. when submit dropzone disappears , profile pic doesnt change.

i expect img attribute filefield. right?

user.userprofile.img = request.post.get('uploaded_image', false) 

please try this.

user.userprofile.img = request.files.get('uploaded_image') # if have multiple files upload user.userprofile.img = request.files.getlist('uploaded_image') 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -