Introduction

Since its early release over half a year ago, version 3 of Django CMS has been under constant development. The latest available developer's package (Beta 3) comes with the promise of an API you can rely on — which is expected not to change much over the publication of RC1.

In this the cloud provider article, we are going to see how to install and get started with this powerful content management system (CMS) that regulars cannot wait to get their hands on. Furthermore, we will try to provide some guidelines that should help with solving the great challenge of upgrading Django CMS from version 2.

Note: If you are interested in installing the currently stable version (version 2 as of March 2014) of Django CMS, check out our article: How to Set Up and Install Django CMS.

Glossary

django cms illustration for: Glossary

1. Django And Django CMS

  1. Django
  1. Django CMS

2. Getting Started: Preparing Your Ubuntu Droplet

3. Installing Django CMS Version 3 Beta 3

  1. Python Virtual Environment For Django CMS
  1. Django CMS And Dependencies
  1. Upgrading To Version 3 From Version 2

4. Configuring Django CMS 3

  1. Creating A New Project
  1. Configuring settings.py
  1. Configuring urls.py
  1. Configuring Templates
  1. Database And Migrations
  1. Running Django CMS

5. Getting Ready For Production

6. Summary

Django And Django CMS

Django

Django is a Python programming language based web-development framework. Being an extremely large project and library, it packs and ships tons of tools and features to developers who are looking forward to getting started quickly.

Django CMS

Django CMS is a truly developer friendly content management system and web-development framework built on top of Django. It makes full use of Django's advanced functionality and offers a pluggable development interface to create web-sites of all sorts.

Being a mature and business-oriented application, Django CMS knows what is valuable. Over the years, the project focused greatly on key areas to make the life easier for both developers hacking on the tool and system administrators alike.

With the release of version 3, Django CMS aims to *change the game* – if you will – and provide a substantially improved interface and an impressive set of features.

Getting Started: Preparing Your Ubuntu VPS

Django CMS is a Python project and you need to tune your system correctly in order to set up and run your web-site without glitches or errors.

If you haven't got your droplet ready for this yet, head over quickly to our Ubuntu/Python article:

And continue with the Django CMS installation (or upgrade) instructions found below.

Installing Django CMS Version 3 Beta 3

Python Virtual Environment For Django CMS

If you haven't already, create a virtual environment:

virtualenv django_env

cd django_env

Or activate it:

source bin/activate

Django CMS And Dependencies

Since Django CMS version 3 has not yet been released, we need to install the application from their Git repository's development branch.

Run the following command to Install Django CMS 3 using pip:

pip install git+git://github.com/divio/django-cms.git@develop#egg=django_cms

And install any database driver you might want to use, e.g.:

pip install psycopg2

One of the most relied upon dependencies is Python Imaging Library (PIL). PIL is used by Django CMS to process images (e.g. cropping, resizing, etc.)

That being said, we will abstain from directly installing PIL and opt for a more accommodating fork of PIL called "pillow". This package is setuptools compatible and automatically solves several issues that would arise if we were to try and use *pil*.

Run the following to install *pillow*:

pip install pillow

Upgrading To Version 3 From Version 2

Run the following command to upgrade Django CMS 3 using pip:

pip install –upgrade git+git://github.com/divio/django-cms.git@develop#egg=django_cms

Note: For upgrades, please take into account that not everything is backwards compatible and things might break. Therefore, please check the Version 3 Beta blog-posts to pick up some additional, helpful upgrade tips.

Configuring Django CMS 3

Getting started with Django CMS is a straight-forward process, but it requires some setting-up. We will begin with bootstrapping the configuration and creating some example templates files that you can use to get going.

Creating A New Project

Being a Django based application, Django CMS comes with some automation, administration, and management tools as well.

In order to create a new project using django-admin, run the following:

django-admin.py startproject dcms

cd dcms

Configuring settings.py

Just like Django, we need to make some changes with the settings.py – the main configuration file.

Run the following command to start editing settings.py using nano text editor:

nano dcms/settings.py

Copy and paste (or modify) the below code-block to the top of the file to have a variable pointing to the base project directory location:

import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

PROJECT_PATH = BASE_DIR

Scroll down and find the column starting with INSTALLED_APPS.

Amend it to look like the following, i.e.:

INSTALLED_APPS = (

'cms',

'mptt',

'menus',

'south',

'sekizai',

'djangocms_admin_style',

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles',

'django.contrib.sites',

)

Continuing, find MIDDLEWARE_CLASSES and modify it to similar to below:

MIDDLEWARE_CLASSES = (

'django.contrib.sessions.middleware.SessionMiddleware',

'django.middleware.common.CommonMiddleware',

'django.middleware.csrf.CsrfViewMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.contrib.messages.middleware.MessageMiddleware',

'django.middleware.clickjacking.XFrameOptionsMiddleware',

'django.middleware.locale.LocaleMiddleware',

'django.middleware.doc.XViewMiddleware',

'cms.middleware.page.CurrentPageMiddleware',

'cms.middleware.user.CurrentUserMiddleware',

'cms.middleware.toolbar.ToolbarMiddleware',

'cms.middleware.language.LanguageCookieMiddleware',

)

Next step is adding the TEMPLATE_CONTEXT_PROCESSORS settings.

Append the below code block to the file:

TEMPLATE_CONTEXT_PROCESSORS = (

'django.contrib.auth.context_processors.auth',

'django.contrib.messages.context_processors.messages',

'django.core.context_processors.i18n',

'django.core.context_processors.request',

'django.core.context_processors.media',

'django.core.context_processors.static',

'cms.context_processors.media',

'sekizai.context_processors.sekizai',

)

Finally, go to the bottom of this file and find the line STATIC_URL. Delete it and instead append the following to suit your needs:

SITE_ID = 1

STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')

MEDIA_URL = '/media/'

TEMPLATE_DIRS = (

os.path.join(PROJECT_PATH, 'templates'),

)

CMS_TEMPLATES = (

('template_1.html', 'Template One'),

)

LANGUAGES = (

('en-us', 'English'),

)

Save and exit by pressing CTRL+X and confirming with Y.

Configuring urls.py

Next step is setting up some URLs, which are configured inside the urls.py file.

Run the following to start editing urls.py using nano:

nano dcms/urls.py

Replace the content with something similar to the following example:

from django.conf.urls import patterns, include, url

from django.conf.urls.i18n import i18n_patterns

from django.contrib import admin

from django.conf import settings

admin.autodiscover()

urlpatterns = i18n_patterns('',

url(r'^admin/', include(admin.site.urls)),

url(r'^', include('cms.urls')),

)

if settings.DEBUG:

urlpatterns += patterns('',

url(r'^media/(?P<path>.*)$', 'django.views.static.serve',

{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),

url(r'', include('django.contrib.staticfiles.urls')),

) + urlpatterns

Save and exit by pressing CTRL+X and confirming with Y.

Configuring Templates

Before creating a database and testing our installation (or upgrade), let's create some templates.

Note: Make sure to define the templates inside the settings.py file first and then create them accordingly.

Run the following to create the template directories and files:

mkdir templates

touch templates/base.html

touch templates/template_1.html

Edit templates/base.html using nano:

nano templates/base.html

With the following example:

{% load cms_tags sekizai_tags %}

<html>

<head>

{% render_block "css" %}

</head>

<body>

{% cms_toolbar %}

{% placeholder base_content %}

{% block base_content %}{% endblock %}

{% render_block "js" %}

</body>

</html>

Save and exit by pressing CTRL+X and confirming with Y.

Edit templates/template_1.html using nano:

nano templates/template_1.html

With the following example:

{% extends "base.html" %}

{% load cms_tags %}

{% block base_content %}

{% placeholder template_1_content %}

{% endblock %}

Save and exit by pressing CTRL+X and confirming with Y.

Database And Migrations

For a new project installation, run the following commands to initiate (or set up) the database:

python manage.py syncdb –all

python manage.py migrate –fake

And perform some checks for integrity:

python manage.py cms check

Note: For an upgrade, run migrations as needed, e.g.:

python manage.py syncdb

python manage.py migrate

python manage.py schemamigration dcms –auto

Running Django CMS

In order to see your Django CMS in action, you can use the test server.

Run the following command to run your application:

python manage.py runserver 0.0.0.0:8000

And visit:

  • Django CMS Home:

http://[your droplet's IP]:8000/en-us

  • Django CMS Admin:

http://[your droplet's IP]:8000/en-us/admin

Getting Ready For Production

When you are finished creating your Django CMS project, you should try to avoid relying on the testing server the application comes with.

For deployments, a fully-fledged web-application server (e.g. Unicorn) must be used, preferably behind a reverse-proxy that will handle the initial processing of requests and distribution of static files [such as images].

To get a quick overall idea of how to go to production, check out the section titles "Getting Ready For Production"in our article: How To Prepare Ubuntu Cloud Servers For Python Web-Applications.

Summary

If you have already been through this article, or if you just want a quick summary of installation instructions to get you started:

aptitude update

aptitude -y upgrade

aptitude install -y build-essential

aptitude install -y cvs subversion git-core mercurial

aptitude install python-setuptools python-dev python2.7-dev python-software-properties libpq-dev

aptitude install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python –

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python –

export PATH="/usr/local/bin:$PATH"

pip install virtualenv

virtualenv django_env

cd django_env

source bin/activate

pip install git+git://github.com/divio/django-cms.git@develop#egg=django_cms

pip install psycopg2

pip install pillow

django-admin.py startproject dcms

cd dcms

href="https://twitter.com/ostezer">O.S. Tezer</a></div>