Forums

app.py file is ignored. only get "Hello from Flask!" default messege

Hello everyone. I have a simple project that i cant get to load on pythonAnywhere. I will try to list the important steps so that my most likely simple mistake can be identified.

I used the ssh method using this guide: https://www.youtube.com/watch?v=4sTZN15J33A I did deploy an even simpler site with this method last year so i dont think that is the issue.

  1. Add ssh key and git copy my repo
  2. create a virtual environment that installs all the files from the requirements.text file
  3. creates an app using the flask template. I select the path: /home/MagnusPytAny/Pizza_Store/app.py . Pizza store is the Repo and app.py is the main file (tried renaming it to main.py but that did not change anything)
  4. added virtual environment path /home/MagnusPytAny/.virtualenvs/myvirtualenv
  5. Reload the website and click on my designated link which then only returns the default "Hello from Flask!"

I have no idea why i get the default message when i have specified the path to the file. And since i dont get any errors either , it is incredibly difficult to troubleshoot what i have missed. I cannot even find the python file that is creating the default message.

Would really appreciate some input on this frustrating issue

[edit by admin: formatting]

What do you have in your WSGI file? There's a link to it on the "Web" page inside PythonAnywhere.

Thanks alot for responding to my issue!

I think i just have the default text:

import sys # add your project directory to the sys.path project_home = '/home/MagnusPytAny/Pizza_Store' if project_home not in sys.path: sys.path = [project_home] + sys.path # import flask app but need to call it "application" for WSGI to work from app import app as application # noqa 

Though I see now that the last line (from app import app as application) has this error message: 'app.app as application' imported but unused

I dont know what this this means either but sounds very important

[edit by admin: formatting]

That warning is something you can ignore; the WSGI file is used to connect your site to our web-serving system, which essentially does something like from your_wsgi_file import application and then uses that application object to handle all incoming requests.

So what that WSGI file is doing is setting up the system path to load modules from /home/MagnusPytAny/Pizza_Store, then importing a WSGI application (which is what a Flask app object is) from /home/MagnusPytAny/Pizza_Store/app.py. What do you have in that file?

Thanks again for your quick response!

OK, so here is what is in my app.py file:

<h1>Note that website is a packaged created with init.py file</h1> <h1>The website module has lots of python files (e.g. models, auth, routes, database et.c)</h1> <h1>The init.py file also has the pretty big create_app function</h1>
from website import create_app app = create_app() if __name__ == "__main__": # app.run(debug=True) app.run(debug=False) 
<h1>Also, where is the information stored that tells python which is the main file? (the one I specified when creating the webapp - app.py)?</h1> <h1>P.S. will use code block formatting next time so the comments does not get formatted as headings</h1>

[edit by admin: formatting]

Can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.

Yes, you guys have my permission to look at all my files / settings etc.

Also, I want to add that the web app runs fine when running it locally.

The app.py in /home/MagnusPytAny/Pizza_Store which is what you are importing from in your wsgi file contains the default flask app that PythonAnywhere gives you when you create a flask app using our quickstart. If that is not what you want your web app to run, then you should import the thing that you want to run in your wsgi file. See https://help.pythonanywhere.com/pages/Flask/#configuring-the-wsgi-file

After reading the link this is what I am supposed to have in my wsgi file:

path = '/home/MagnusPytAny/Pizza_Store' if path not in sys.path: sys.path.insert(0, path) from app import app as application 

the first app is the main file (i could rename it to main.py) that has a function that creates the flask object. The object created is named 'app' as well. I still only get the default message. app.run() is in the if __name__ == "__main__" block as the docs mention.

I just cant figure why the default flask message is still being shown now that the wsgi file is directly importing my app object from my app.py file that is in my Pizza_Store folder.

[edit by admin: formatting]

I think I solved it now!

The issue was very weird! When I git copy my repo and also used git pull a few times, for some reason the app.py file was the same as the default one that pthonAnywhere provides. Whenever i pulled from my github the file did not get overwritten and it was my fault that i did not check that it was my file that was actually run. Since all the other files were correct I did not notice.

So the git pull didn't work for app.py file specifically for some reason so i had to manually delete and upload the correct file and then it worked. I have no idea why or how this happened. Now even with the solution in hand i don't think i did anything wrong, however , it is on me for not noticing that one app.py did not get overwritten as it should have been.

I would like to thank you guys for the help!

Ah, that would explain it! Normally if you've modified a file, git won't overwrite it. Let's say you check out a particular version of your code. If you then change a file, and do a git pull, it will just leave the changed file as it was. It will only warn you if you try to pull a newer version of your repo -- and even then it will only be if the file in question had been changed on git in the meantime.