The last time we spoke of Django, we installed Django CMS: perhaps the most popular out-of-the-box CMS available for Django. Now that we've explored the most popular CMS let's move on to the best CMS (probably).
I realize I'm speaking of something subjective as though it were fact. As much as I'd like to agree that this is wrong, doing so would make for a boring read. I'll stick to my guns here.
We'll start with the obligatory server updates and Python3 setup. This way, the copy-and-paste crew will have no problem following along.
Dependencies & Environment
Note that this example assumes you're running a Ubuntu/Debian server. If you're using a Mac, I'm confident you can figure out the equivalent commands by now (hint: brew update and brew upgrade):
This is the part where we should cover the installation of Python3, pip3, Python3-dev, and so forth. Luckily, we covered this subject in a previous post with extreme detail. If you're not familiar with Python installation, I highly recommend managing your system's Python versions in this post:
Setup Environment & Dependencies
As with any Python project, we pick a directory and set up shop by creating a Virtual Environment. You should recognize the steps below as
Navigating to a system directory.
Creating a virtual environment (named .venv in this example).
Activating the above virtual environment.
Great. With the environment activated, we can start getting to work. Before installing Wagtail, we need to install two dependencies: libjpeg and zlib. These are libraries critical to image compression and the sort:
Now we can finally install Wagtail:
Good job. For our next trick, we'll create our actual Wagtail project. This installation contains Django at its core: install Wagtail with install Django and create the necessary project structure.
wagtail start mysite
wagtail start mysite is a command that will create a "project" called mysite in the current directory. Again, name your project as you see fit. With that directory created, change directories, so you're inside said project, and install Wagtail dependencies from the requirements.txt file:
As with a typical Django project, we need to run our migrations to get things set up.
This command will result in the following output:
Next, we need to create a superuser:
Running this will prompt a few details as follows:
You're a hero. Now, you're probably anxious to see what all the fuss is about. Let's get your development server up and running so you can start playing around in the browser:
That command should give you the following output:
Great work. Now if you visit your server's default address on port 8000, you should be able to hit the barebones Wagtail project you just created. To reach the admin, hit https://localhost:8000/admin/.
As mentioned, installing Wagtail will immediately set up a Django project. If that's so, where is our famous settings.py file? It's split into three files: base.py, dev.py, and production.py. All these are stored here:
base.py is the closest to Django's settings.py file. This contains all settings common to our dev and prod environments.
As you might imagine, settings stored in either dev.py or production.py are specific to dev or production, respectively. dev.py comes with some presets, such as setting DEBUG to True, as well as a pre-populated SECRET_KEY:
Unlike dev.py, production.py comes with no such predetermined values. The understanding is that you must set these values yourself: after all, if anybody were to grab hold of the secret kept in production.py, your career as a developer is over: