I am trying to find out how to read an uploaded CSV without saving it to disk ...
I'm stuck at form.cleaned_data['file'].read ... I don't seem to get any output
If I can only figure out how to get output, then I can write an appropriate function to deal with the lines of data.
#addreport.html
<form enctype="multipart/form-data" method="post" action="/products/addreport/"> {%csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit" />
#forms.py
from django import forms
#
class UploadFileForm(forms.Form):
file = forms.FileField()
--
# views.py
def addreport(request):
if request and request.method == "POST":
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
print form.cleaned_data['file'].read()
else:
print form.errors
print request.FILES
#form = UploadFileForm()
else:
form = UploadFileForm()
return render_to_response('products/addreport.html', {'form': form},context_instance=RequestContext(request))