in contribution python ~ read.

Installing spirit forum on your django website with Mandrill

I've found out this beautiful full-featured forum site and wanted to integrate it to my website on a separate subdomain (e.g. It wasn't easy though.

It is also necessary to set up an email server allowing you to send confirmation emails (for registration) and to retrieve forgot passwords. For this I used Mandrill - free email service which does all the work for you.

Why spirit?

  • super clean, simple and nice environment
  • easy to use - even as a user and also as a administrator
  • support last versions of software! - this should not be underestimated. It support django 1.8 and of course Python 3.4. Glory! No these stupid prehistoric solution for Python 2.

The only problem is documentation. There is simply none. So tweaking the site falls to searching for particular phrases using grep and trying... Hence, this tutorial.

Why Mandrill?

  • free up to 12k emails per month
  • easy to integrate to django thanks to djrill


We will integrate spirit to our current django site, which is deployed by gunicorn and nginx (but it is independent part). spirit forum will run on different domain and will be treated as different site, because of it's highly dependent settings file.

Clone and install spirit

download spirit form github by git clone If you need, edit it to your needs before installation. For example, I decided to use new Pillow 2.8.1 instead of 2.6 and switched to experimental branch, which has django 1.8 support. Then activate your virtualenv and install it by pip install <path_to_cloned_spirit>/Spirit.

Settings for two sites

Now we will prepare project for having multiple sites. We will split to two parts - one common for both spirit and your regular site and second part which is related to your regular site.

We need to create new SITE_ID for each site. In this example it's SITE_ID=1 for the main domain/site, e.g. SITE_ID=2 is for, where we want to have spirit forum.

Then create third file for your spirit settings file. Now, you should have three settings files. The main one, which is common for both (definition of static and media dir, language, zone, databases...), then, where is at least from spirit.settings import * and SITE_ID = 2 (for now). The third one with whatever you had in you and clash with settings for spirit settings file. Plus, you should have SITE_ID=1 in this settings file. In both files and you should paste from common import *.

Put these three files into e.g. <project_name>/settings/. Example here

Next thing we need to create twice (not necessarily, but for simplicity yes) you need to create two and, where you set insert new name of settings file instead the old one <project_name>.settings. So the line with the setting file should look like this: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<project_name>.settings.spirit")

Finally, create and In the first one leave everything as you have now and the second add to urlpatterns: url(r'^', include('spirit.urls')),. According to this changes, you need to add this to your spirit settings file ROOT_URLCONF = '<project_name>.urls_spirit' and same for the mysite part.

That can be found here

Mandrill settings

First, install djrill by pip install djrill.

Now we need to setup Mandrill. You need to create an account there and generate API key (that is easy). Add this to

INSTALLED_APPS += ( "djrill",)

MANDRILL_API_KEY = "j4kdhyYx7w" # EXAMPLE of your mandrill key  
EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend"  
DEFAULT_FROM_EMAIL = "" # fill by your email of course  

Syncing, cache and routing

Since now you need to specify settings file when using Let's syncdb for both projects by running:

python migrate --settings=<project_name>.settings.spirit  
python migrate --settings=<project_name>.settings.mysite  

then run:

python createcachetable spirit_cache --settings=<project_name>.settings.spirit  

and finally:

python collectstatic --settings=<project_name>.settings.spirit  

nGinx and Gunicorn

You just need to add new special server for spirit subdomain. E.g.:

upstream spirit {  
    server unix:<path_to_gunicorn_socket_file>/spirit.sock;

server {  
    listen 80;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass   http://spirit;
    # something here, like location, alias...

upstream mainserver {  
    server unix:<path_to_gunicorn_socket_file>/main.sock;

server {  
    listen 80;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass   http://mainserver;
 # something here for you...

And finally, let gunicorn server the sites to these socket files, at which nGinx listens.

gunicorn mw.wsgi_blog:application --bind=unix:main.sock  
gunicorn mw.wsgi_spirit:application --bind=unix:spirit.sock  

All sources can be found on github

That's all :) . Enjoy