简体   繁体   中英

'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')

我认为您正在寻找request.FILES而不是request.FILE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM