Skip to content

Notes and research on deploying a Django app to PythonAnywhere for Django Girls #1

@copelco

Description

@copelco

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

  1. 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 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.
    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 some webapp commands, but appears to have some specific django support too.
    • AFAICT, the django commands 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.

Idea 1 - Run bash commands through the PythonAnywhere API

  1. User creates a free PythonAnywhere account and generates an API token in the web console.

  2. 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"
  3. Use pa or pythonanywhere-core to create a new PythonAnywhere web app.

  4. Use the PythonAnywhere API to run bash commands 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

  5. Use the PythonAnywhere API to reload the web app.

  6. Open the web app in a browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions