Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'WSGIRequest' object has no attribute 'FILE'

I want to make an app that takes excel file and reads its content, without using form and models.

I keep getting the error in the title and I would to know what the error is.

This is my HTML:

<div style="width: 800px; margin: 0 auto;">
    <form enctype="multipart/form-data"  action="." method='POST'> {% csrf_token %}
        <input type="file" name="excelfile">
        <input type="submit" value="Submit" />
    </form>
</div> 

This is my view:

def uploadexcelfile(request):
    if request.method == "POST":
        excel = request.FILE['excelfile'].read()

        print('Opening workbook...')

        wb = openpyxl.load_workbook(excel)
        activesheet = wb.active
        print(activesheet.title)

        sheet = wb.get_sheet_by_name(activesheet.title)

        print('Reading rows...')
        for row in range(1, sheet.max_row + 1):
            url = sheet['A' + str(row)].value

            print(url)
    else:
        return render(request, 'uploadexcelfile.html')
like image 447
ottomd Avatar asked Aug 23 '17 12:08

ottomd


1 Answers

I think you're looking for request.FILES instead of request.FILE.

like image 90
nik_m Avatar answered Oct 23 '22 08:10

nik_m