Skip to content

wagtail-examples/tutorial-deploy-pythonanywhere-paid

Repository files navigation

Wagtail CMS site deployed to PythonAnywhere

This is a tutorial about one way to build and deploy a Wagtail CMS site to PythonAnywhere.

It's a starting point that has most of the elements one might need (backend and frontend) to build a Wagtail site and deploy it live. It's by no means a complete site, in fact I've intentionally left out a lot of the things that make a site unique, such as the design, content, and custom code so that you can use this as a starting point for your own site.

I recommend you read:

The official Wagtail documentation and Developer Documentation, specifically Your first wagtail site

I wanted to document the process I go through. I've actually built and deployed a fair few Wagtail sites over the last decade using various hosting platforms, as a freelancer. I now work for Torchbox as a developer.

The code here is the complete source code after following the steps below.

  • ✅ Python:3.10
  • ✅ Mysql Database
  • ✅ Node / webpack to build the frontend
  • ✅ CI actions for code checks
  • ✅ Pre-commit to run git hooks
  • ✅ Wagtail CMS v5.1.1
  • ✅ Django 4.2

Because I'm using git push to deploy the webapp and that requires SSH access, I am using a paid account on PythonAnywhere, which starts at €5/month.

Overview of required steps

Local setup

Initial repo and starting a new Wagtail project

  • Stating of with a new remote repo on Github (or similar) I clone it locally and start a new Wagtail project then install the python dependencies and start a new Wagtail site.
  • I adjust the layout of the site generated by Wagtail to suit my preferences.

Setup to use Mysql

  • Prepare to use a Mysql database in a docker container for local development. This is optional, but I prefer to use a local database that is the same as the one used when it's deployed live.
  • Configure Wagtail to use the Mysql database via environment variables.
  • Add further configuration settings to use environment variables.

The site can be run locally at this point

PythonAnywhere setup

Set up a webapp and bare-repo on PythonAnywhere

  • Create a new webapp, database, bare-repo, virtualenv, environment variables on PythonAnywhere.

Add further deployment settings

  • Update the post-receive hook to run the deployment and adjust the WSGI file on PythonAnywhere.

Start a deployment

  • Push your first deployment.

The site can be viewed on PythonAnywhere at this point.

Optional (recommended) steps

There's more that could be done, here's a few extra guides.