November 9, 2015

Mezzanine for the Uninitiated: How We Built industrydive.com

Old industrydive.com front page

New industrydive.com home page

Old industrydive.com front page (left) and the new one (right)

Industry Dive is a digital media company that publishes business news and original analysis for 2 million executives in 11 industries through publications like Retail Dive and Marketing Dive . Our corporate site, industrydive.com , doesn't get as much traffic as the publication sites, but it's an important way for potential partners, advertisers, and employees to learn about us.

When we set out on a major redesign of industrydive.com, we had to choose between upgrading our ancient Django-based Mezzanine site or switching to a new CMS entirely. We chose Mezzanine as the CMS for our corporate site so any of our employees can add a job listing, create an individual profile page, or upload images without help from our developers. We switched from WordPress to Mezzanine a couple of years ago as a way to migrate into an environment we could further customize and integrate with our Django-based site. With our recent corporate site upgrade, we switched from Mezzanine 1.4.6 to 4.0.1.

Despite its strengths, Mezzanine can be difficult to implement as its an abstract layer that permeates and circumvents Django on many levels. Want to create template variables before you render? Dont write a view, write a Page Processor. Want to direct a page URL to a specific template? Dont create a URL pattern, populate the pages slug field. After much trial and error, weve documented a series of these and other gotchas to provide an overview for integrating Mezzanine into an existing Django project.

How to Implement Mezzanine

The following instructions are from an environment using Mezzanine 4.0.1 and Django 1.8.4

  • Install Mezzanine:
  • pip install mezzanine
  • In your apps settings.py
  • Add any or all of the following Mezzanine packages to INSTALLED_APPS after any Django packages but before your existing Django app:

    "mezzanine.boot",
    "mezzanine.conf",
    "mezzanine.core",
    "mezzanine.generic",
    "mezzanine.blog",
    "mezzanine.forms",
    "mezzanine.pages",
    "mezzanine.galleries",
    "mezzanine.twitter",
    "mezzanine.accounts",
    "mezzanine.mobile"

  • Add these to TEMPLATE_CONTEXT_PROCESSORS:

    "mezzanine.conf.context_processors.settings",
    "mezzanine.pages.context_processors.page",

  • Add the MIDDLEWARE_CLASSES youd like to use. For example:

    "mezzanine.core.middleware.UpdateCacheMiddleware",

  • Any Mezzanine-specific settings can be overridden at the top of your settings.py file. For example, to require password change verification via email:

    ACCOUNTS_VERIFICATION_REQUIRED = True
    DEFAULT_FROM_EMAIL = 'webmaster@yoursite.com'

  • In your app's urls.py:
  • from mezzanine.core.views import direct_to_template

  • If youd like to redirect to your own index.html:

    url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),

  • After all of your URLs, add:

    ("^", include("mezzanine.urls")),

  • After urlpatterns, add:

    handler404 = "mezzanine.core.views.page_not_found"
    handler500 = "mezzanine.core.views.server_error"

At this point you might create a new Mezzanine project or start up a theme directory (containing templates and static files) in tandem with an existing Django project. Well talk about the latter option in our next post. For now, note that Mezzanine provides several packages to choose from depending on what features youd like to implement. Their documentation covers each packages functionality, classes, and available middleware. In our case, we make heavy use of blog and pages. Our next posts will cover Mezzanine-specific components (themes, page processors, and template directory structures), inheriting from Mezzanine models, and configuring Mezzanine settings.

Topic
###