-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
My running notes and research on developing a PythonAnywhere plugin for django-simple-deploy.
Background
- The Django Girls tutorial contains a deploy section that explains how to deploy a Django app to PythonAnywhere. Sometimes users get stuck at this step and it can be frustrating.
- django-simple-deploy aims to simplify the initial deployment process for Django applications, and includes support for fly.io, Heroku, and platform.sh. However, these services require a credit card to sign up, which can be a barrier for some users. PythonAnywhere offers a free tier that allows users to deploy small Django applications without needing a credit card.
- The goal of this effort is to explore creating a PythonAnywhere plugin for django-simple-deploy that automates the deployment of Django applications to PythonAnywhere, if possible.
Running questions
- The Beginner: Free! plan allows hosting an app, but PostgreSQL appears to be a paid feature. Is that a blocker for django-simple-deploy, which uses PostgreSQL by default?
Research
- PythonAnywhere provides 512MB of disk space for free accounts, which theoretically could be used to store the SQLite database file that's used in the Django Girls tutorial.
- PythonAnywhere has an API to perform various tasks, including running bash commands.
- pythonanywhere-core is a Python client library for the API.
- PythonAnywhere doesn't have Docker support. Based on the Django Girls tutorial, it seems that users set up their Django apps using the Python Anywhere interface and web-based bash console.
- The tutorial includes a pa_autoconfigure_django.py script that automates some of the setup steps, including pulling from your public GitHub repo:
pip3.10 install pythonanywhere pa_autoconfigure_django.py --python=3.10 https://github.com/<your-github-username>/my-first-blog.git
- PythonAnywhere has a cli tool,
pa. It supports somewebappcommands, but appears to have some specificdjangosupport too.- AFAICT, the
djangocommands are meant to be run from within a PythonAnywhere bash console, not locally, which isn't really compatible with django-simple-deploy. However, some of the code could be useful.
- AFAICT, the
Idea 1 - Run bash commands through the PythonAnywhere API
-
User creates a free PythonAnywhere account and generates an API token in the web console.
-
User sets environment variables locally, following the pattern established by
pa, for example:export API_TOKEN="<your_api_token>" export PYTHONANYWHERE_SITE="<your_username>.pythonanywhere.com"
-
Use
paor pythonanywhere-core to create a new PythonAnywhere web app. -
Use the PythonAnywhere API to run
bashcommands to:- Pull from the user's public GitHub repo
- Set up a virtual environment
- Install dependencies
- Set up static files
- Run migrations
- Configure the web app to point to the Django app's WSGI file
Running bash commands through the API is a bit clunky. It could work, or maybe
-
Use the PythonAnywhere API to reload the web app.
-
Open the web app in a browser.
Metadata
Metadata
Assignees
Labels
No labels