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.
settings.py
urls.py
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 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.
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.
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
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
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.
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.
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
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.
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.
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
.
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.
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:
http://[your droplet’s IP]:8000/en-us
http://[your droplet’s IP]:8000/en-us/admin
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.
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.
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.