This is how it's supposed to look like:
upload_form.html:
<form method="POST" enctype="multipart/form-data" >
{% csrf_token %}
{{ form.as_p }}
<input type="submit" name="submit" value="Submit" >
</form>
view (based on the example from the docs):
from django import forms
class UploadFileForm(forms.Form):
up_file = forms.FileField()
def handle_uploaded_file(f):
with open('some/file/name.xls', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
from django.http import HttpResponseRedirect
from django.shortcuts import render
def upload(request):
if request.method == "POST":
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['up_file'])
return HttpResponseRedirect('/upload_done/')
form = UploadFileForm()
return render(request, 'upload_form.html', {'form': form})
This is merely a skeleton. There's no data handling, no error handling, nothing regarding the view after redirection. Even if you are under deadline pressure, you wouldn't be able to manipulate this example without some minimal understanding of the framework. So take the time to go over the tutorial. I can't stretch this enough. It's not long, and very detailed.
edit
I updated the example to a full file-handling example using the django forms. I find it weird to use a form for handling but then saving the file using a function, but seeing as this is how the documentation does it, I'm not gonna go another way