Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

django - Pandas 1.2 Update - pd .read_excel no longer imports file from form - Path Error

I am using Django to select an Excel (xlsx) file from a form. (This is a Foundation html.)

   <form action="{% url "edit:add_trades" %}" method="post" enctype="multipart/form-data">

        {% csrf_token %} 

            <label for="FileUpload" class="button">Upload File</label>
            <input type="file" id="excel_file" class="show-for-sr">


     </form>

Before using Pandas 1.10 and xlrd 1.2 all worked well with this code:

This is the view code:

if request.method == 'POST':

    file = request.FILES [ 'excel_file' ]

    file_name, file_type = os.path.splitext ( file.name )

    // check for xlsx file type

    if str ( file_type ) != '.xlsx':
        msg = "Sorry, not a .xlsx file." 
        messages.warning ( request, msg )
        return redirect ( '/edit/index' )

    # get the excel data 

    df = pd.read_excel ( file, sheet_name = 'orders',  index_col = None, header = None )

When I update to pandas 1.2 I get a file error:

FileNotFoundError at /edit/add_trades/
[Errno 2] No such file or directory: '63P-11955.xlsx'
Request Method: POST
Django Version: 2.2.16
Exception Type: FileNotFoundError

I also get this error when updating the xlrd.

What changed in this Pandas update and the path from a Django form?

Using python 2.8 and Django 2.2.16.

Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...