INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
# To this:
INSTALLED_APPS = (
# FeinCMS:
'feincms',
'feincms.module.page',
'feincms.module.medialibrary',
'cms',
# Django Standard:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
Note: If django.contrib.admin is commented (# django.contrib.admin), comment it out.
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',
)
The database engine which comes pre-configured is the SQLite 3. If you wish to use a different one other than the standard, you need to configure and define it here as well. Scroll down the file and find the DATABASES configuration block. Once there, edit it as necessary, e.g.:
# Default SQLite:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# PostgreSQL example:
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'name',
# 'USER': 'user_name',
# 'PASSWORD': 'pwd',
# 'HOST': 'host.add.ress',
# 'PORT': '5432',
# }
# }
Once you are done with the database settings, it is time to define some template directories.
Add the following line somewhere suitable on the file:
TEMPLATE_DIRS = (
# List of template directories.
# Example:
os.path.join(BASE_DIR, 'templates'),
)
Configure URLs (urls.py)
Edit urls.py configuration file using nano:
nano feincms_app/urls.py
Replace the contents with something similar to below, suiting your needs:
import os
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^media/(?P.*)$', 'django.views.static.serve', {
'document_root': os.path.join(os.path.dirname(__file__), 'media/')}),
url(r'', include('feincms.contrib.preview.urls')),
url(r'', include('feincms.urls'))
) + staticfiles_urlpatterns()
==== Creating The First Model ====
As we have mentioned at the beginning, FeinCMS is more of a framework than a plain, everything-extracted CMS. It requires models to be defined in order to work. Therefore, before creating the database schema, we need to define the models.
Execute the below command to start editing models.py of cms Django app we created:
vim cms/models.py
And replace the content of the file with the following to create a new model:
from feincms.module.page.models import Page
from django.utils.translation import ugettext_lazy as _
from feincms.content.richtext.models import RichTextContent
Page.register_templates({
'title': _('General FeinCMS Template Example'),
'path': 'template1.html',
'regions': (
('header', _('Page header.')),
('main', _('Main content area.')),
('sidebar', _('Sidebar'), 'inherited'),
('footer', _('Page footer.')),
),
})
Page.create_content_type(RichTextContent)
Note: To learn more about page models, check out the official documentation for a detailed example: FeinCMS Page Module.
==== Initiate The Database ====
After the configurations, it is time to initiate the database and create the models / database schema.
Run the following to create the database:
python manage.py syncdb
Once you execute this command, you will be asked a series of questions, e.g.:
# You just installed Django's auth system,
# which means you don't have any superusers defined.
# Would you like to create one now? (yes/no):
yes
# ^^ Create an admin account by answering the questions.
# For testing purposes you can opt for:
# Username: admin
# Password: admin
==== Creating The Template ====
Let's create our template model, which will be used to render the model from the previous step.
Create the templates directory:
mkdir feincms_app/templates
Run the following to create the first template file using nano:
nano feincms_app/templates/template1.html
And copy-and-paste the below template contents, modifying to suit your needs:
{% block header %}
{% for content in feincms_page.content.header %}
{{ content.render }}
{% endfor %}
{% endblock %}
{% block content %}
{% for content in feincms_page.content.main %}
{{ content.render }}
{% endfor %}
{% endblock %}
==== Test The Application ====
Run the following command to run a sample application server:
python manage.py runserver 0.0.0.0:8000
You can check out your installation by visiting the admin section of FeinCMS on your droplet:
http://[your droplet's IP]:8000/admin
Note: To terminate the test server, press CTRL+C.
Create Your First Content
Visit the admin section by going to:
http://[your droplet's IP]:8000/admin
Login with admin credentials you have set and press "Log In".
Note: You might need to use the defaults for logging in - admin and admin respectively.
Create a page by pressing the "Add" button found next to "Pages" on the list.
And that's it!
==== 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"on our article: How To Prepare Ubuntu Cloud Servers For Python Web-Applications.
Summary
If you have already been through this article once, or, if you do not fancy copy-pasting commands one by one, here is a quick summary of installation instructions to get you started up until configurations:
# 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 feincms_env
cd feincms_env
source bin/activate
pip install feincms
# Create a CMS project:
django-admin.py startproject feincms_app
cd feincms_app
python manage.py startapp cms
# And continue with configurations ..