我遵循了本教程http://www.script-tutorials.com/pure-html5-file-
upload/,在php部分中,我替换为:
class UploadImageView(LoginRequiredMixin, CurrentUserIdMixin, View): @method_decorator(csrf_protect) def dispatch(self, *args, **kwargs): return super(UploadImageView, self).dispatch(*args, **kwargs) def post(self, request, username): path = 'myproject/media/pictures/guitar.jpg' f = request.FILES['image_file'] destination = open(path, 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() return HttpResponse("image uploaded")也改变了这行
<form id="upload_form" enctype="multipart/form-data" method="post" action="."> {% csrf_token %}


