Let me preface this by saying I am familiar with Python as a data tool, but this is my first go around with Python/Flask.... I was working my way through the Flask Mega Tutorial book - and decided to try making a dashboard for the company sales team. I have just started and I can't figure out what I have done wrong.
Here is the link to my project on Github I think it's because the imports are circular?? But I'm not sure how to fix it. My app.py file creates the app and then it get imported to routes.py and models.py. The routes.py relies on the models.py for my User class. I can run it as it is locally and it says the Flask application is running but I am getting a 404 error in the browser.
if __name__ == "__main__":
app.run(debug=True)
should be placed at end of routes.py
, not in app.py
.
Reading from this answer:
When the Python interpreter reads a source file, it executes all of the code found in it.
Before executing the code, it will define a few special variables. For example, if the Python interpreter is running that module (the source file) as the main program, it sets the special
__name__
variable to have a value__main__
. If this file is being imported from another module,__name__
will be set to the module's name.
So above code will be executed only if you run your app.py
. If you run routes.py
it will become meaningless, unless it's placed inside routes.py
module.
I tested it and it works as expected: