Mezzanine Documentation
repository·master·Indexed 26 days ago
https://github.com/stephenmcd/mezzanineA highly extensible content management platform built on top of the Django framework. Mezzanine provides out-of-the-box features including blogging, e-commerce, and hierarchical navigation. Documentation covers admin customization, blog importing from platforms like WordPress and Blogger, hybrid caching strategies using two-phased rendering, and a flexible settings system via register_setting.
What's inside Mezzanine
- Mezzanine is a powerful, consistent, and flexible content management platform built on the Django framework. It provides an integrated architecture for managing pages, blog posts, form data, and store products. Unlike many other platforms that rely heavily on external modules, Mezzanine provides most of its core functionality by default, resulting in a more efficient and integrated platform.
Getting started with Mezzanine
masterMezzanine is a high-level CMS built on top of Django. To use Mezzanine effectively, you must have a working knowledge of Django. The core philosophy is that "Mezzanine Is Just Django."
Depending on your role, you should focus on the following areas:
- Front-end developers: Explore inline-editing to learn how to implement features that allow content authors to edit content directly on the page.
- Back-end developers: Study the content-architecture to understand how to extend Mezzanine with custom content types, or use model-customization and admin-customization for low-level modifications.
- System administrators: Review deployment requirements and the caching-strategy for production environments.
Understand Mezzanine Multi-Tenancy
masterMezzanine supports multiple sites within a single running instance by leveraging Django's
sitesapp. Unlike standard Django, which typically uses theSITE_IDsetting to bind a project to one site, Mezzanine uses a priority-based pipeline to determine the active site for a request. This allows true multi-tenancy where different domains (or subdomains) can serve different content from the same process.The site determination pipeline follows this order:
- Session variable
site_id: Used by the admin to allow users to switch between sites. - Host matching: The domain of the current HTTP request is compared against the domain names in the
Siterecords. - Environment variable
MEZZANINE_SITE_ID: Used for contexts outside of HTTP requests (e.g., management commands). Mezzanine's custommanage.pyhandles the--site=IDargument. SITE_IDsetting: The fallback if no other method identifies a site.
- Session variable
Key Features of Mezzanine
masterMezzanine includes a wide range of built-in features for content management and site administration:
- Content Management: Hierarchical page navigation, save as draft/preview, scheduled publishing, drag-and-drop page ordering, and WYSIWYG editing.
- Site Customization: In-line page editing, custom templates per page/post, and configurable dashboard widgets.
- Forms & SEO: Drag-and-drop HTML5 forms builder (with CSV export) and SEO-friendly URLs/meta data.
- E-commerce: Includes the
Cartridgeshopping cart module. - Communication & Social: Multi-lingual site support, social sharing (Facebook/Twitter), and integration with Disqus, Gravatar, and Google Analytics.
- Extensibility: API for custom content types, search engine and API, and seamless integration with third-party Django apps.
- Other: Blog engine, tagging, Akismet spam filtering, and bit.ly integration.
Understand Mezzanine Content Architecture
masterMezzanine content is built using abstract models from
mezzanine.coreandmezzanine.pages. The two primary models for building custom content types are:mezzanine.core.models.Displayable: An abstract model for content that has a URL (slug) but is not part of the site's navigation (e.g., blog posts, calendar events). It provides metadata, auto-generated slugs, publishing status, and searchability.mezzanine.pages.models.Page: A concrete model that extendsDisplayableand implements a hierarchical navigation tree. This is the foundation for most site content.
Key abstract building blocks include:
SiteRelated: Adds adjango.contrib.sites.models.Sitefield.Slugged: Implementstitleandslug.MetaData: Provides SEO fields (title,description,keywords).TimeStamped: Providescreatedandupdatedtimestamps.Ownable: Adds a related user field for authorship.RichText: Provides a WYSIWYG editable field.Orderable: Enables drag/drop ordering.
Run the test suite with pytest
masterTo verify your changes, install the testing dependencies using the[testing]extra and runpytest. If the test suite is too large, you can run specific test files to save time.Add Mezzanine to an existing Django project
masterTo integrate Mezzanine into an existing project, you must configure the necessary settings and
urlpatterns. Refer to theproject_templatedirectory in the Mezzanine repository for reference. Key configuration areas include:INSTALLED_APPSTEMPLATESMIDDLEWAREPACKAGE_NAME_GRAPPELLIandPACKAGE_NAME_FILEBROWSER(for Grappelli and Filebrowser integration)- The call to
mezzanine.utils.conf.set_dynamic_settingsat the end ofsettings.py.
Modify Mezzanine templates
masterMezzanine templates are located in the
templatesdirectory of each individual Django app. To modify them:- Locate the template in the Mezzanine app directory (e.g.,
mezzanine/core/templates/base.html). - Copy the template into your project's local
templatesdirectory. - Modify the local copy.
Alternatively, you can use the
collecttemplatescommand to copy templates automatically:python manage.py collecttemplatesNote: Once copied to your project directory, these templates will always override the original Mezzanine templates, even after upgrades.
python manage.py collecttemplates --help- Locate the template in the Mezzanine app directory (e.g.,
Implement Page Processors to extend Page logic
masterSince all
:class:.Pageinstances are handled by the singlemezzanine.pages.views.page` view, you cannot create custom views for specific page types. Instead, use Page Processors.Page Processors are functions associated with a custom
:class:.Page model that are called during the view process. They receive two arguments:requestand thepageinstance.Return values:
- A dictionary: The keys/values are added to the template context.
- An
HttpResponse(or subclass): This overrides the defaultmezzanine.pages.views.pageview entirely (useful for handling form submissions via redirects).
Setup:
- Create a module named
page_processors.pyinside one of yourINSTALLED_APPS. - Use the
@processor_for(Model)decorator to associate the function with a specific model. - Alternatively, use
@processor_for(slug='your-slug')to run the processor only when a specific page slug is matched.
from django import forms from django.http import HttpResponseRedirect from mezzanine.pages.page_processors import processor_for from .models import Author class AuthorForm(forms.Form): name = forms.CharField() email = forms.EmailField() @processor_for(Author) def author_form(request, page): form = AuthorForm() if request.method == "POST": form = AuthorForm(request.POST) if form.is_valid(): # Form processing goes here. redirect = request.path + "?submitted=true" return HttpResponseRedirect(redirect) return {"form": form}Override Mezzanine settings with Django settings
masterMezzanine's settings system integrates with standard Django settings in two ways:
- Overriding Defaults: You can override any setting registered via
register_settingby defining it as a standard variable in your project'ssettings.py. This is useful for overriding non-editable settings from third-party apps. - Unified Access: The
mezzanine.conf.settingsobject provides a single access point for both Mezzanine-registered settings and standard Django settings.
Note: If a setting is marked as
editable=True, defining it in your project'ssettings.pywill always override the value stored in the database.- Overriding Defaults: You can override any setting registered via
Add your site to the Mezzanine gallery
masterIf you have built a site using Mezzanine and want to feature it in the project's gallery, you can do so by submitting a pull request to the Mezzanine repository.
Submission Requirements:
- Fork the project.
- Create a pull request adding your site to the list.
- Important: Omit the trailing slash in your site's URL, as the project manually adds it during the featuring process.
Import blogs from Blogger
masterTo import from Blogger, you must first obtain your
Blogger IDfrom your Blogger settings (found in the browser URL asBlogID=XXX). Additionally, you must setAllow Blog FeedstoFullin theSite Feedsettings to ensure all data is retrieved.Limitation: The import is truncated if there are more than 500 blogs or 500 comments per blog.