Forums

problem importing app as application

I can't get my app to import and below is the error I'm seeing. I think it must be to do with my init.py file but I don't know why. The app runs fine locally and this is my first time deploying to pythonanywhere.

When I run the app locally from the command line I use:

flask --debug --app quizapp run

when I use

from quizzapp import app as application

it fails.

My init.py file has a "create_app()" function which initialises Flask and returns app. I think this should be called automatically but perhaps I need to do things differently to work with WSGI?

Any advice much appreciated.

Below is error from my log file

2022-11-27 23:31:51,890: Error running WSGI application 2022-11-27 23:31:51,893: ImportError: cannot import name 'app' from 'quizapp' (/home/quizme/quiz-project/quizapp/init.py) 2022-11-27 23:31:51,893: File "/var/www/quizme_pythonanywhere_com_wsgi.py", line 71, in <module> 2022-11-27 23:31:51,893: from quizapp import app as application # noqa

Function is not called automatically. You need to call it.

Thanks I worked it out.

in the WSGI file I used the following and it worked fine.

from myapp import create_app # noqa

application = create_app()

cheers.

Glad you worked it out!