def createlist(request):
if request.method == 'POST':
files = request.FILES['ListFile']
print(type(files))
csv_file = csv.DictReader(files)
for i in csv_file:
print(i)
return HttpResponse("ok")
This gives
class 'django.core.files.uploadedfile.InMemoryUploadedFile'
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Here i post this file using ajax
js:
$('#form1').ajaxForm(function(data) {
alert(data) ;
});
Using codec.iterdecode, i solved it.I think this is due to python 3.x
import codecs
def createlist(request):
if request.method == "POST":
fil = request.FILES['ListFile']
csvfile = csv.DictReader(codecs.iterdecode(fil, 'utf-8'))
for i in csv_file:
print(i)
return HttpResponse("ok")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With