简体   繁体   中英

dead simple Django file uploading not working :-((

I am trying desperately to do a very simple file upload with Django, without (for now) bothering with templating & co.

My HTML is:

 <form 
      id="uploader" 
      action="bytes/"
      enctype="multipart/form-data" 
      method="post"
  >
      <input type="file" name="uploaded"/>
      <input type="submit" value="upload"/>
  </form>

My Python is (knowing it is a POST):

if path=="bytes/":
        if 'uploaded' in request.FILES:
            return HttpResponse("you uploaded a file")
        else:
            return HttpResponse("did not get the file")

I don't understand why I'm always getting the "did not get the file" message...

Can anyone help me, please???

Try changing " if 'uploaded' in request.FILES: " to " if request.FILES ".

You might want to take a look at the documentation as well; there's an example-- http://docs.djangoproject.com/en/dev/topics/http/file-uploads/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM