Installing Mezzanine on Ubuntu with Apache and mod_wsgi

Modifying the Theme

Mezzanine does not create the template files inside your site (and we do not want to modify Mezzanine’s files), so we will store a copy inside our site and modify them from there. We want to the directory structure for the templates to be exactly the same as that of Mezzanine.

Note: On Ubuntu, Mezzanine (and templates) are located under your Python folder. For instance, on my Ubuntu install, Mezzanine is located at:


Open terminal and navigate to your site’s root directory. First we are going to create a Django app and then we are going to create the the relevant folders inside the app.

cd /srv/www/mysite startapp mythemeapp (or whatever you want to call it)
cd mythemeapp
mkdir static
cd static
mkdir css img js
cd ..
mkdir templates
cd templates
mkdir includes

Now that we have the app and the structure in place, we are going to get all the template files and place them in our Mezzanine project (not the mythemeapp). Navigate to your project.

cd /srv/www/mysite/mysite

Remember our mysite project is located within the mysite folder. Your heiarchy should be:


Now run the collecttemplates command to copy all of the template files.

python collecttemplates

After running this command, a templates folder (and files) will be copied to your project.

Now copy the relevant template files to your mythemeapp’s template folder. You do not need to copy everything – only the files that you intend to change. To start, copy these three files:

/templates/includes/footer_scripts.html (the Javascripts are contained here).

Now that the template structure is in place, we have to tell Mezzanine that our app mythemeapp exists.

Open up and add the mythemeapp to Installed Apps.

?View Code PYTHON


We also have to change template directory to point to your new files. Search for TEMPLATE_DIRS in your file and change it to point the mythemeapp template folder.

?View Code PYTHON

Now the changes you make to the mythemeapp template files will be reflected on your website.

Collecting Static Files

Before we make any css updates, we need to move all static files to our project folder. The Mezzanine static files are located in the same location as the template files. If we using Python’s runserver command instead of using Apache/wsgi, the static files would be served automatically.

We are not going actually move the static files. Instead we are going to create a symbolic link that points to all of the static files. First we have to update our static root location. Open up and change your static root.

?View Code PYTHON
Static Root = '/srv/www/mysite/mysite/static'

Now we will use Django’s collectstatic command. The collectstatic command will collect all of the static files (css, images, etc) and place them in the static root folder. You have the option of copying all of the files to the location or create a symbolic link to all of the files.

Open terminal.

cd /srv/www/mysite/mysite

Now run the command:

python collectstatic --link --noinput

The –link option tells the command to create a symbolic link. The –noinput option is so that you won’t get prompted for any input.

Note: Use the –dry-run option when you want to change what will be changed, but there will be no updates to the file system.

python collectstatic --link --dry-run --noinput

Now restart Apache and view your website:

sudo service apache2 restart

Modifying CSS

Mezzanine uses three css files (bootstrap.css, bootstrap_responsive, and mezzanine.css). As with the templates, We do not want to change Mezzanine’s CSS files, so copy the CSS files to the CSS folder under the mythemeapp.

Next we need to run the collectstatic command again to symlink the CSS files from mythemeapp to your project’s static folder.

python collectstatic --link --noinput

Now you can make changes to your CSS files without affecting Mezzanine’s default CSS.

Note: You also have the option of creating your own CSS files. Just create a custom.css (or whatever you name you like) in the CSS folder of your mythemeapp app and reference the file in the base.html template. You will also need to run the collectstatic command again.

Now reboot Apache and view your website.

That’s it. It’s a bit more work than just using Python’s virtual environment, but using Apache and WSGI with Mezzanine is not that difficult.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks