[Python] Issue reading CSV file with Pandas for Flask App

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm creating a Flask app using python and am having an issue pulling data out of the file. Whenever I visit my website I get 'Internal Server Error'.

    It's a very basic setup, I have the CSV saved in a folder 'static'. However I can't seem to be able to access through flask.

    Really appreciate any advice here. Have tried a ton of solutions and can't get anything to work. Thanks!

    from app import app
    from flask import Flask
    from flask import request
    import pandas as pd

    @app.route('/hello', methods=\['GET', 'POST'\])
    def helloIndex():
    df = pd.read_csv('/static/filename.csv')

    # would put basic python script to run the input data against the data in the CSV here


    if request.method == 'POST':
    output2 = '<b> output data here <>'
    return output2
    return '''
    <form method="POST">
    < HTML here for input data would go here >
    </form>
    '''

    Continue reading...

Compartilhe esta Página