Can't get Uploaded File into DictReader
I'm trying to upload a CSV file specified by the user in a form and
then parse it using DictReader. Everything seems to be working until
I initialize DictReader with the uploaded file. As soon as I try to
access any value in the row, it throws an odd exception. Am I doing
something wrong or is the UploadedFile object incompatible with
DictReader?
if request.POST:
form = ImportFileForm( request.POST, request.FILES )
if form.is_valid():
try
csvfile = request.FILES['filename'].read() # reads entire file
reader = csv.DictReader( csvfile, 'r' )
for row in reader:
group_name = str.strip( row['Group Name'] )
#
throws exception "Group Name"
except Exception, e:
print e
else:
form = ImportFileForm()
return render_to_response('admin_import_from_excel.html', {'form':
form,}, RequestContext(request) )
Thanks in advance for any assistance.
Jeff
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home