'Flask and passenger setup?
Looking for best practices advice on deploying a Flask app. My hosting provider has passenger available. I have a basic structure of:
~/home/me/dev.domain.com
└── public
└── cgi-bin
└── ...
The hosting company tells me that I need a passenger_wsgi.py at the level of the public dir.
My project roughly looks like:
.
├── app
│ ├── __init__.py
│ ├── static
│ │ ├── css
│ │ ├── images
│ │ └── js
│ ├── templates
│ │ ├── layout.html
│ │ ├── main.html
│ │ └── other.html
│ └── views
│ ├── __init__.py
│ └── main.py
└── app.py
My question is: Where should the venv live? Inside the public folder or at the same level as public
~/home/me/dev.domain.com
└── passenger_wsgi.py
└── venv
└── public
├── app
│ ├── __init__.py
│ ├── static
│ ├── templates
│ └── views
└── app.py
or
~/home/me/dev.domain.com
└── passenger_wsgi.py
└── public
├── venv
├── app
│ ├── __init__.py
│ ├── static
│ ├── templates
│ └── views
└── app.py
Solution 1:[1]
I have the following working:
My question was about the project layout to make deployment easier. My current solution is
$ tree -d
.
+-- passenger_wsgi.py
+-- public
¦ +-- static
¦ ¦ +-- LIB
¦ ¦ +-- css
¦ ¦ +-- images
¦ ¦ +-- js
¦ +-- templates
¦ +-- views
+-- requirements.txt
+-- venv
Basically, I renamed the default Flask app folder to public. My passenger_wsgi.py script now looks like:
import os
import sys
INTERP = os.path.join(os.path.abspath('.'), 'venv/bin/python3')
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
from public import create_app
cwd = os.path.abspath('.')
sys.path.append(cwd)
sys.path.append(os.path.join(cwd, '/public')) # You must add your project here
sys.path.insert(0, os.path.join(cwd, 'venv/bin'))
sys.path.insert(0, os.path.join(cwd, 'venv/lib/python3.9/site-packages/'))
application = create_app()
It looks like the contents and operation of a passenger_wsgi.py file is hosting platform dependant. I had to make sure that my venv for the site was in my path before I did anything else. This looks nothing like the example in my provider's FAQ.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 7 Reeds |
