Forums

Trouble with Flask loading Dictionary

I have a python script that returns a dictionary. I am trying to access that dictionary in a python flask file and display it in an html file using a template. When I try and load the webpage, I get "Something went wrong :-(" If I comment out the flask components of the file and add a print statement and tell the function to run, it will print out the dictionary from the other script. If I use a simple script containing a test dictionary and remap the flask python file to this, it will display the website. I feel like I am missing something obvious, but I can't see it. The computation python file is giving me the directory, which can be read and printed by the app file, but it won't pass the data on to the html page when setup that way.

# flask app to launch scoreboard

from flask import Flask, render_template
import harknessScoreboard
#import testDict

app = Flask(__name__)
app.config["DEBUG"] = True

@app.route("/scoreboard")
def scoreboard():
    weeklyPointsDict = harknessScoreboard.main()
    #weeklyPointsDict = testDict.main()
    #weeklyPointsDict = {"Julian": 25, "Bob": 26, "Dan": 47, "Cornelius": 3}
    return render_template("scoreboard.html", weeklyPointsDict=weeklyPointsDict)
    #print(weeklyPointsDict)

#scoreboard()

harknessScoreboard.main() returns the dictionary when I print without the flask parts of the script, but won't seem to pass anything to the return statement.

What do you see in the logs? (You can find link to logs on the "Web" page),

First, thanks for telling me where the logs were. Was having trouble finding them. I don't understand it not finding the file, as it finds it when running as a regular python file not a flask file.

2024-09-23 15:54:16,831: Error running WSGI application 2024-09-23 15:54:16,860: FileNotFoundError: [Errno 2] No such file or directory: 'poolwidepicks_8455.xls' 2024-09-23 15:54:16,860: File "/var/www/harknessfb_pythonanywhere_com_wsgi.py", line 16, in <module> 2024-09-23 15:54:16,860: from flask_app import app as application # noqa 2024-09-23 15:54:16,861: 2024-09-23 15:54:16,861: File "/home/HarknessFB/mysite/flask_app.py", line 4, in <module> 2024-09-23 15:54:16,861: import harknessScoreboard 2024-09-23 15:54:16,861: 2024-09-23 15:54:16,861: File "/home/HarknessFB/mysite/harknessScoreboard.py", line 250, in <module> 2024-09-23 15:54:16,861: main() 2024-09-23 15:54:16,862: 2024-09-23 15:54:16,862: File "/home/HarknessFB/mysite/harknessScoreboard.py", line 186, in main 2024-09-23 15:54:16,862: pickDict, valueTeams = getPicks() 2024-09-23 15:54:16,862: 2024-09-23 15:54:16,862: File "/home/HarknessFB/mysite/harknessScoreboard.py", line 18, in getPicks 2024-09-23 15:54:16,862: weeklyPicksHTML = open("poolwidepicks_8455.xls", "r") 2024-09-23 15:54:16,863: ******* 2024-09-23 15:54:16,863: If you're seeing an import error and don't know why, 2024-09-23 15:54:16,863: we have a dedicated help page to help you debug: 2024-09-23 15:54:16,863: https://help.pythonanywhere.com/pages/DebuggingImportError/ 2024-09-23 15:54:16,863: *******

I have tried having the file in both the main and static folders with the path set accordingly, with the same error logs.

See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

Thank you so much!

Let us know if you need more help.