1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # Function to handle an uploaded file.
def handle_uploaded_file(f,title):
tt = '%s' % title
PATH = MEDIA_ROOT + tt +'.xls'
with open(PATH, 'wb+') as destination :
for chunk in f.chunks():
destination.write(chunk)
destination.close()
def file_upload(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['filed'],form._raw_value('title'))
return HttpResponseRedirect('/home/')
else:
form = UploadFileForm()
return render_to_response('home/File_Upload.html', {'form': form},context_instance=RequestContext(request)) |