An example reproduced by the Django Documentation .
from django.http import HttpResponseRedirect from django.shortcuts import render_to_response def upload_file(request): if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): handle_uploaded_file(request.FILES['file']) return HttpResponseRedirect('/success/url/') else: form = UploadFileForm() return render_to_response('upload.html', {'form': form}) def handle_uploaded_file(f): destination = open('some/file/name.txt', 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close()
You can replace 'some / file / name.txt' with another path where you want to save this file.
source share