Mark McAulay

"Big kids did it" 
« Back to blog

Installing django-cms

NOTE: I have re-posted this due to fixing a couple of errors I had. It should be fine now but if you do find something wrong, just leave me a comment and i'll update as needed.

I am working on Ubuntu 9.10 here, not windows or mac...sorry, although I dont expect things will be much different for mac at least...if I get a chance i'll run through this process on windows too and update the article but no promises.

I'm assuming that Python, Django and sqlite3 are installed already. For reference, I am currently using Python 2.6.4 and Django (trunk version) 1.2.

I have lifted a good chunk of this from the official django-cms installation guide, the rest came from googling and trial and error. I found the official guide a little above my head so thought i'd keep notes on what I had to do to get this running.


Aaaannnnyway...

If you dont already have one, create a new folder for your code to live in. My folder lives in my home directory and is named "django_apps". This will pop up throughout this guide so if you're following along and you call yours something else, remember to replace "django_apps" with the name of your own folder when the time comes.

In a terminal, move into your code directory:

CD ~/django_apps

Create a new Django project (call this whatever you like but remember to change it if you're following along and have called it something else):

django-admin.py startproject project-name

No harm in making sure that all is indeed well with Django at this early stage so:

CD project-name

And...

python manage.py runserver 

Head on over to 127.0.0.1:8000 and if you see "it worked" then well, its working

Here comes the science...

If you dont happen to know your Python location then issue the following command:

which python
(my one is "/usr/local/lib/python2.6" for example)


Go to your Python dist-packages directory "your-python-path/dist-packages"
 
Download the latest and greatest Django CMS from here: http://www.django-cms.org/en/downloads/ (at the time of writing, this is version 2.0.2)

Unzip the downloaded file into the "dist-packages" directory...you will need to do this as "sudo" unless you have your system set up wrongly ;)

Make copies of the following directories like so: 

sudo cp -R digi604-django-cms-2.0-c0288a1/cms/ cms
sudo cp -R digi604-django-cms-2.0-c0288a1/mptt/ mptt
sudo cp -R digi604-django-cms-2.0-c0288a1/publisher/ publisher

Do a bit of house cleaning to get rid of all the files you don't need:

sudo rm -rf digi604-django-cms-2.0-c0288a1.zip
sudo rm -rf digi604-django-cms-2.0-c0288a1/

Head back to the project you created previously

cd ~/django_apps/project-name

In your editor, edit "settings.py" like so:

On lines 1+2 put the following before anything else:
import os
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

Then, after the import statements , add this:

gettext = lambda s: s

Set up the remainder of the file with the following changes/additions:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/path/to/your/data/your-db-name.db/

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

ADMIN_MEDIA_PREFIX = '/media/admin/'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'cms',
    'cms.plugins.text',
    'cms.plugins.picture',
    'cms.plugins.link',
    'cms.plugins.file',
    'cms.plugins.snippet',
    'cms.plugins.googlemap',
    'mptt',
    'publisher',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.locale.LocaleMiddleware',  
    'cms.middleware.page.CurrentPageMiddleware', 
    'cms.middleware.user.CurrentUserMiddleware', 
)

TEMPLATE_DIRS = os.path.join(PROJECT_PATH, 'templates')
(templates being the name of my template dir within project-name)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth', 
    'django.core.context_processors.i18n', 
    'django.core.context_processors.request', 
    'django.core.context_processors.media', 
    'cms.context_processors.media',
)

(I didnt have a "TEMPLATE_CONTEXT_PROCESSORS" specified so had to add all of the above anew.)

Set up your available templates (dont worry that they dont actually exist right now, its not that important. Perhaps i'll write about templates next as I discover more.)
CMS_TEMPLATES = ( 
    ('base.html', gettext('default')), 
    ('2col.html', gettext('2 Column')), 
    ('3col.html', gettext('3 Column')), 
    ('extra.html', gettext('Some extra fancy template')),

Next, Edit your "urls.py" file like so:

urlpatterns = patterns('', 
    (r'^media/(?P<path>.*), 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT } ), 
    (r'^admin/', include(admin.site.urls)),
    (r'^', include('cms.urls')),
)

Create a folder called 'media' in your project root (that's "project-name" for me), this means you create a symbolic link from the "cms/media/cms" folder in "dist-packages" to your new "media" folder:

ln -s /usr/local/lib/python2.6/dist-packages/cms/media/cms cms

Now for the magic...if you're not already there:

cd ~/django_apps/project-name

and...

python manage.py syncdb

If all goes well, you'll be asked if you want to set up your superuser account...which of course you do so just follow the instructions in the terminal.

That should hopefully be that. If your development server is still running in your terminal stop it, then restart it again just to be sure.

cmd c
python manage.py runserver

Visit http://127.0.0.1:8000/ to make sure all is well, you'll be greeted with appropriate text and if you can see the django-cms logo then your media folder is cool also.

log in via the admin link and enjoy :)

Comments (7)

Feb 26, 2010
phoebebright said...
Thanks for this - Also had to fix csrf error by adding {% csrf_token %} after form tags - see this report: http://github.com/digi604/django-cms-2.0/issues/issue/286
May 27, 2010
 said...
Hi

I did the steps here (I have Django 1.2.1 and Django-cms 2.1.0 beta).

Everything works fine, I log into admin and add a page.

But I'm not able to add any content, no plugins are listed. Have I missed something?

May 28, 2010
derek said...
I see that Markdown is now available. Might be worth "refactoring" some of these posts.
Jun 03, 2010
Afrowave said...
@TorvBB I got to the same place. No Templates. Is it possible we need to create our own?
Jul 08, 2010
treasonx said...
I really want to use django-cms. It seems like a great platform but installation is just too difficult. I tried to install it several times and I hit a wall everytime I do. I have django 1.2.1 and django-cms 2.1.0 beta. Installation seemed to be going pretty smooth. Then I tried to add a page and got a message saying it was missing template TemplateDoesNotExist at /admin/cms/page/add/ I looked into the templates directory and it seems like page/add is just missing there is no add directory.
Jul 08, 2010
treasonx said...
Okay figured it out, doh! I need to make some templates!
Jul 09, 2010
derek said...
Mark, have you managed to get it running under Apache/wsgi yet? Those would be very useful notes to add here...

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     Connect     twitter