I'm trying to run a Flask script that queries an SQLite database and displays a Rest API only for inside the network. It is going to be served on Windows Server 2012 running Apache 2.4 with mod_wsgi. I'm also using Python 3.7.
The error I'm getting in the error log is:
File "D:/sites/cifsearch/website/web.wsgi", line 7, in <module>\r, referer:
http://IP Address/ from app.py import app as application\r, referer:
http://IP Address/ ModuleNotFoundError: No module named 'app'\r, referer: http://IP Address/
web.wsgi is on the same directory as app.py
This is what I have written on web.wsgi. I copied and pasted this from what I could find on google as I'm still very new to this.
import sys
import logging
logging.basicConfig (stream=sys.stderr)
sys.path.insert(0,'/')
from app.py import app as application
I also commented out:
if __name__ == "__main__":
app.run()
in app.py as per this site: https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/. But I don't think the request is even getting that far. I'm suspecting, it's probably path related or permissions?
Your application is not set up as a package, so the import in your wsgi code gives you the ModuleNotFoundError
.
Put your application in a directory called e.g. myapp
and add an __init__.py
file to the directory containing
from .app import app
to make it a package.
Your directory structure should look like this:
web.wsgi
myapp/
app.py
__init__.py
Then change your import
line in the wsgi file to
from myapp import app as application