Tutorial

How To Install Django CMS Version 3 Beta 3 With Django 1.6 on Ubuntu

Published on February 26, 2014
author

O.S. Tezer

How To Install Django CMS Version 3 Beta 3 With Django 1.6 on Ubuntu

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 DigitalOcean 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


1. Django And Django CMS


  1. Django
  2. Django CMS

2. Getting Started: Preparing Your Ubuntu Droplet


3. Installing Django CMS Version 3 Beta 3


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

4. Configuring Django CMS 3


  1. Creating A New Project
  2. Configuring settings.py
  3. Configuring urls.py
  4. Configuring Templates
  5. Database And Migrations
  6. 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:

How To Prepare Ubuntu Cloud Servers For Python Web-Applications

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:

# Remember to enter the directory:
# cd [django_env]
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.:

# PostgreSQL:
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:

# Usage: python django-admin.py startproject [project name]
# Example:
django-admin.py startproject dcms

# And enter the application directory:
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:

# Usage: nano [project dir. name]/settings.py
# Example:
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:

# -*- coding: utf-8 -*-
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 = (
    
    # Additional plugin examples
    # e.g.:
    # Django CMS CK Editor:
    # https://github.com/divio/djangocms-text-ckeditor
    # 'djangocms_text_ckeditor',

    # Django CMS:
    'cms',
    
    # Utilities:
    'mptt',
    'menus',
    'south',
    'sekizai',
    
    # Other CMS modules:
    'djangocms_admin_style', 

    # Django:
    '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:
    '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',

    # Django CMS:
    '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 = (

    # List of template directories.
    # Example:
    os.path.join(PROJECT_PATH, 'templates'),

)

CMS_TEMPLATES = (

    # List of templates.
    # Example:
    ('template_1.html', 'Template One'),

)

LANGUAGES = (

    # List of languages.
    # Example:
    ('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:

# Usage: nano [project dir. name]/urls.py
# Example:
nano dcms/urls.py

Replace the content with something similar to the following example:

# Django CMS 2:
# from django.conf.urls.defaults import *
# Django CMS 3:
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

# OVERALL RESULTS
# ===============

# 1 checks skipped!
# 8 checks successful!

# Installation okay

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

python manage.py syncdb
python manage.py migrate

# For schema migrations:
python manage.py schemamigration dcms --auto

# ! Remember to replace dcms with your project name. 

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:

# Preare the system and install Python tools:
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

# Create a virtual environment:
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

# Create a Django CMS project:
django-admin.py startproject dcms
cd dcms

<div class=“author”>Submitted by: <a href=“https://twitter.com/ostezer”>O.S. Tezer</a></div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
O.S. Tezer

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Very nice. It’s great to have the detail and the accurate links to related tutorials. Please can you do some more - ie How to customise templates or add an app.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.