Wagtail is a CMS, made on top of Django framework. Why Wagtail, you ask. Well first thing first, Python is my favorite programming language, and naturally I’ll look building a website using Django. I’ve researched a bit about what CMS to use with Django, and I found there are three CMS-es out there that are stand out from the rest: Django-CMS, Mezzanine, and Wagtail. I chose Wagtail simply because I think it has the most modern look, easy to customize, and has this killer feature, StreamField.
First thing first, this post is from a web developer who had essentially ZERO knowledge about Django and Wagtail. So if you’re an seasoned Django dev, please bear with me! Also, I’m mainly using OSX Yosemite and Ubuntu 14.04 for development, so, sadly I can’t comment about Windows.
First let’s install the dependencies: Python, pip, and PostgreSQL
Now we’ll install virtualenv. This is not necessary, but will improve our development greatly as virtualenv will let us have clean and reproducible Python development environment.
And then, register virtualenvwrapper to our shell. Add these lines to your .bashrc
(Ubuntu) or .zshrc
(OSX).
Then, you’ll need to log out to apply the change.
Now, we’ll create new virtualenv for our blog, then install Wagtail.
Now we’ve scaffolded our blog project structure! We can start our development now. However, by default, Wagtail uses SQLite for its database, which is alright for development purpose. For production environment, I strongly recommend to use more heavy duty database, namely PostgreSQL. So let’s make Wagtail uses PostgreSQL.
Open up the requirements.txt on your project directory, then uncomment this line that says psycopg2==2.5.2
. This will tell pip to install psycopg2 dependency which is needed for Python to interface with PostgreSQL. After that run:
There are some hurdles though, when using PostgreSQL for the first time. I’m experienced with database, but mainly with Oracle and MySQL. PostgreSQL is a bit different and coming from that MySQL it’s hard at first.
What we want to do is to:
- Create a user, matching our blog name
- Create a database, also matching our blog name
- Give that user access to the database
Of course, you can use whatever name you want, but same name will simplify our live, so hey why not. So, run this:
Now we’re inside PostgreSQL shell. We’ll create the user, then grant the permission to yourblogname database.
Then use CTRL+D
to exit psql and type exit
to exit user postgres’ shell.
Now we have to tell our blog to use PostgreSQL instead of SQLite. In your yourblogname/settings/base.py
, comment out SQLite database entry:
Then, uncomment PostgreSQL entry, and fill it with our database information:
One of the problem I encountered was because I set HOST
to be empty, which in turn will use socket connection, and gave me this error:
So, make sure to fill HOST
with localhost
or 127.0.0.1
After that, we’ll write our initial database to PostgreSQL:
Also, don’t forget to create an admin account so that we could get inside the admin panel.
If everything is good, then we have our database ready, and we’re ready to actually code our blog!
In the next post, I’ll guide you to create our blog post model, home page, and the templates.