Django upload only the data of a file

0

I'm working on the managed interface of Django, I've tried in different ways to popular tables with files xls , csv or txt without success, I know how to upload a file but not just use the data, or failing that upload the file and then or during the process I sent the data to the database. Any ideas?

    
asked by Anthony 25.08.2017 в 19:55
source

1 answer

0

Hello first, make sure that the file is uploading, now you can read the content of a csv , for example, in the following way:

if request.FILES and request.POST:
    csvfile = request.FILES.get('filename', None)
    readCSV = csv.reader(csvfile, delimiter=',')
    for row in readCSV:
        print(row)

for a serious text file:

f = codecs.open(request.FILES['filename'], encoding = 'utf-8')
data = f.readlines()
    
answered by 25.08.2017 в 20:10