The problem
I am trying to run my first Flask applications while following the CS50 Javascript course. I have made succesfully implemented a few of the examples of the class. However I got a 500 Internal Server Error as I tried to run the following piece of code:
Code 1
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
if __name__ == "__main__":
app.run()
I run the code in the terminal by calling the name of my python app as such:
python app.py
What I tried
1. I tried running a more simple example:
Code 2
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "hello world!"
if __name__ == "__main__":
app.run()
Since I was able to run this without a problem I decided to get back to the previous example. However I haven't been able to figure out the solution. The syntax seems to be correct. To be sure I compared the code letter for letter with that of the video.
I noticed that the teacher of the video ran the application differently using:
set FLASK_APP = app.py
flask run
I tried that. This seemed to work too for a while.
Becoming frustrated I tried many of the things that worked before and even the simplest pieces of code such as code 2 seem to yield that 500 internal Server Error.
2. At some point I thought there might be a problem with flask which led me to reinstalling it.
What could be causing this? This is not the first time I have encountered this problem. Evertime it seems to "resolve" itself when I quit using the computer for a while which makes me none the wiser.
How do I find a solution online to a problem that I can merely define this broadly? The 500 Internal Server Error isn't really giving me hints.
[Edit:] I'm currently on a vacation at the hotel working on the local wifi. Could that have an impact on my server?