We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install And Get Started With FeinCMS

PostedMarch 5, 2014 10.8k views Django

Introduction

One of the several popular options available for a Django based content management system (CMS) is FeinCMS. Being more of a framework in the sense of a Django-upgrade, it is possible to simply create relatively complex websites and applications using FeinCMS.

In this DigitalOcean article, we are going to introduce you to this interesting tool and show you how to get started using FeinCMS content management system framework.

Glossary

1. Django In Brief

2. FeinCMS

  1. FeinCMS Advantages

3. Getting Started: Preparing Your Ubuntu Droplet

4. Installing FeinCMS

  1. Python Virtual Environment
  2. Install FeinCMS And Its Dependencies

5. Working With FeinCMS

  1. Create A Project
  2. Initiate FeinCMS As A Django App
  3. Configure Project's Settings (settings.py)
  4. Configure URLs (urls.py)
  5. Creating The First Model
  6. Initiate The Database
  7. Creating The Template
  8. Test The Application
  9. Create Your First Content

6. Getting Ready For Production

7. Summary

Django In Brief

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.

FeinCMS

FeinCMS is technically more of a framework than a plain content management system. The tool itself tries to provide a good base with a lot of additional functionality - together with helpers - on top of standard Django for developers to create websites easily, without having to refer to many additional add-ons.

Unlike traditional CMS tools, using FeinCMS requires a little bit of getting-used-to. This, however, brings a lot of flexibility with it, simply because certain complex tasks become much easier to achieve with the tool. For example, in order to work with FeinCMS, you must define data types (i.e. content data) and if you require such complex operations, this might be the tool for you to develop your application on.

Although you need to do some additional work to get what you specifically require, FeinCMS' helpers, like the out-of-the-box ready-to-use administration area, make it great to manage your custom content.

FeinCMS Advantages

  • Flexible: Out of all Django based CMS systems, FeinCMS is the most flexible one by nature.

  • Customisable: All content types are user (i.e. developer) created and minted - therefore rendering FeinCMS highly customisable.

  • Well documented: Although not the best, FeinCMS documentation is relatively good.

  • Feature rich: FeinCMS extracts a lot of the complexity from the developer with many tasks.

Getting Started: Preparing Your Ubuntu Droplet

FeinCMS is a Python project and you need to prepare your system correctly in order to set up and run your web-site in a solid fashion.

If you haven't got your VPS ready, head over quickly to our Ubuntu/Python article:

And continue with the FeinCMS installation instructions found below.

Installing FeinCMS

We are going to make use of Python virtualenv to install and set up FeinCMS, together with its dependencies. In this section, we will begin with creating an environment and continue thereon.

Python Virtual Environment

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

virtualenv feincms_env
cd         feincms_env

And have the environment activated:

source bin/activate

Install FeinCMS And Its Dependencies

Run the following command to install feincms_env using pip:

pip install feincms

# Successfully installed feincms Django django-mptt Pillow feedparser

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

# PostgreSQL:
# pip install psycopg2

# MySQL:
# pip install mysql-python

# Note: For additional DB drivers, remember
#       to install OS level DB packages.

Working With FeinCMS

Create A Project

Working with FeinCMS is almost the same as a regular Django project.

Follow the below instructions to create a new project:

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

# Enter the application directory:
cd feincms_app

Initiate FeinCMS As A Django App

Next, we need to initiate FeinCMS as a Django application before configuring the new Django project we created.

Run the following to create a FeinCMS Django app:

python manage.py startapp cms

Configure Project's Settings (settings.py)

Similar to Django CMS, we need to configure the Django project we created. This will mostly consist of adding FeinCMS as an installed application, followed by deciding on the database engine to use.

Let's edit the settings.py file using the nano text editor:

nano feincms_app/settings.py

Scroll down the file and find the section entitled INSTALLED_APPS and change it:

# From this:

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'),

)

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

Configure URLs (urls.py)

Run the following to 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<path>.*)$', '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()

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

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:

nano 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)

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

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:

<div id="header">
    {% block header %}
    {% for content in feincms_page.content.header %}
        {{ content.render }}
    {% endfor %}
    {% endblock %}
</div>

<div id="content">
    {% block content %}
    {% for content in feincms_page.content.main %}
        {{ content.render }}
    {% endfor %}
    {% endblock %}
</div>

<div id="sidebar">
    {% block sidebar %}
    {% for content in feincms_page.content.sidebar %}
        {{ content.render }}
    {% endfor %}
    {% endblock %}
</div>

<div id="footer">
    {% block footer %}
    {% for content in feincms_page.content.footer %}
        {{ content.render }}
    {% endfor %}
    {% endblock %}
</div>

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

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 ..
Submitted by: O.S. Tezer

0 Comments

Creative Commons License