How to deploy a small python flash application on PythonAnywhere
The project directory name is airtable_gallery, under a parent called titan. I will preserve these names for convenience. It is handy to have a parent direcory for storing notes, debug dumps, backups that don't go into the git repository. A virtual environment tool is used (mkvirtualenv)
~/titan/
~/titan/airtable_gallery/.git
~/titan/airtable_gallery/requirements.txt
~/titan/airtable_gallery/app.log
~/titan/airtable_gallery/*.pickle
~/titan/airtable_gallery/app/app.py
~/titan/airtable_gallery/app/*.py
~/titan/airtable_gallery/app/templates/
~/titan/airtable_gallery/app/assets/
Final testing and cleanup.
Save the virtual environment
pip freeze > requirements.txt
git remote add origin https://[email protected]/tropis/airtable_gallery.git
git push -u origin master
My account is gobot. Choose domain gobot.pythonanywhere.com for now.
Choose Manual Configuration, not Flask because my own directory design.
Choose Python 3.6
Source code: /home/gobot/titan/airtable_gallery
Working dir: /home/gobot/titan/airtable_gallery
Path to Virtual env: /home/gobot/.virtualenvs/airtable_gallery
Static files: /assets/ /home/gobot/titan/airtable_gallery/app/assets
git config --global user.name "Phil Hardaker"
git config --global user.email [email protected]
# Create base directory only.
mkdir ~/titan
cd ~/titan
# Pull my repo, brings .git too
git clone https://[email protected]/tropis/airtable_gallery.git
mkvirtualenv --python=/usr/bin/python3.6 airtable_gallery
# Now paths set to virtualenv, see indicator (airtable_gallery)
# Install project libs
cd ~/titan/airtable_gallery
pip install -r requirements.txt
File location:
ls /var/www/gobot_pythonanywhere_com_wsgi.py
But just use the Edit link on Web tab. We will include the secret AIRTABLE_API_KEY to be available in the environment.
import sys
import os
os.environ["AIRTABLE_API_KEY"] = "key11111"
path = '/home/gobot/titan/airtable_gallery/app'
if path not in sys.path:
sys.path.append(path)
from app import app as application
Click "Reload" after any change to redeploy.
http://gobot.pythonanywhere.com