The 80% solution to bootstrapping a new Django site: models, views, templates for basic publishing
APACHE-2.0 License
Common Content provides models, views, and templates for common web content in a reusable Django app, giving you a blog-like web site out of the box.
Django ships with flatpages
, the most simplistic content model possible. Third party
tools like Wagtail or DjangoCMS
provide flexible and complex content management workflows, but require a lot of custom
code. Common Content is designed to fill the gap between these options. If you need
pages and feeds for your Django site, but don't need (or want) the power and complexity
of a full content management system, Common Content may be the right tool.
Common Content includes a set of templates using the Bootstrap CSS framework based on the examples found on the bootstrap website. The templates work with any objects that implement the common data model. They can easily be coupled with Django's generic class-based views to produce a clean and professional site quickly and easily. If you use the included concrete models with the default templates and the included views, you'll be starting with a basic blog-style site.
Common Content is still Alpha-level software. It has many completed features that are usable in production. However, test coverage is not yet complete, the feature set is still growing, and there are likely to be breaking changes before the software reaches a stable 1.0 release. Be aware that migrating to newer versions may require some work.
Common Content defines a data model based on Schema.org, extended in some places using fields from the open graph protocol, or other web standards. It provides concrete Django models for common web objects, as well as an abstract CreativeWork and BasePage model for extending the available page types.
Common Content provides the following Content:
HomePage
- A dedicated model for site home pages. Sites can have multiple HomePagesPage
- A model for evergreen pages like "About".Article
- Like a Post in Wordpress, the Article is the main content type of theSection
- Articles are contained in sections. A section is like a category.Image
- An Image model is provided to house image uploads and their metadata,django-imagekit
(see the section below on Images).Attachment
- A model for storing non-image file uploads and their metadata.Author
- A model to encapsulate author information, including default copyrightCommon Content provides views and templates (using Bootstrap 5) for each type, along
with a few different options for list display. The templates include Open Graph metadata
and Schema.org metadata for social sharing and SEO. The templates load the Bootstrap CSS
and JavaScript from a CDN by default, so there's nothing else to install and little or
no front-end to deal with (but you can override this in your own templates, see the
bootstrap_styles
block below).
In addition to the content pages, Common Content also provides:
Menu
and Link
- These models define a list of links that can be used to implementAbstractCreativeWork
and BasePage
- These are abstract Django models that you canadmindocs
app.django-sitevars
- Site variables store bits of information that are reused acrossdjango-tinymce
Support - If django-tinymce
is installed, Common Content will useThis project uses uv from Astral for managing development. Install uv before working with this repo.
After checking out the code, you can bootstrap a development environment by running:
uv sync
uv run ./manage.py migrate
Add the following to your settings.py
:
import commoncontent.apps
INSTALLED_APPS = [
*commoncontent.apps.CONTENT,
# Optionally use tinymce in the admin
"tinymce",
# Other Django apps here
"django.contrib.redirects", # Required
"django.contrib.sites", # Required
# sitevars must come AFTER contrib.sites for admin to work
"sitevars",
]
# Ensure your middleware includes the following:
MIDDLEWARE += [
"django.contrib.sites.middleware.CurrentSiteMiddleware",
"commoncontent.redirects.TemporaryRedirectFallbackMiddleware",
]
# If using tinymce
TINYMCE_DEFAULT_CONFIG = commoncontent.apps.TINYMCE_CONFIG
# Add `commoncontent.apps.context_defaults` to your context processors. You will also
# need to add the request, auth, and messages context processors if not already there.
# The inject_sitevars processor should come after context_defaults so you can override
# the default values using sitevars.
# Probably looks like this:
TEMPLATES = [
{ "BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"commoncontent.apps.context_defaults",
"sitevars.context_processors.inject_sitevars",
],
},
},
]
In your project's urls.py
, insert the Common Content URLs where you want them. To have
Common Content manage your home page and top-level pages, make it the LAST url pattern,
and list it like this:
from commoncontent import views as generic
urlpatterns = [
# Common Content provides templates for auth pages
path("accounts/", include("django.contrib.auth.urls")),
# You need to add the admin yourself. Remember to add the docs!
path('admin/doc/', include('django.contrib.admindocs.urls')),
path("admin/", admin.site.urls),
# TinyMCE urls if desired
path("tinymce/", include("tinymce.urls")),
# All other urls are handed to Common Content
path("", include("commoncontent.urls")),
]
The following documentation should help you use Common Content.
The Common Content base template is divided into major blocks that can be replaced in your child templates. The blocks, in order of appearance, are:
title
: The content of the HTML page title tag.bootstrap_styles
: An HTML block that by default pulls in the bootstrap stylesheet.{{ block.super }}
and then add some tweaks.opengraph
: Used to expose the page's open graph metadata in the HTML head. This isschema
: Holds the schema.org metadata.extra_head
: Override this if you need to include custom CSS, web fonts, etc. in thebody_class
: A block you can override to apply a custom class to the HTML bodyheader
: A block to contain your site's masthead and main navigation, the headerprecontent
: A block that appears before the main content of the page. Override thiscontent
: The main content body of the page. By default, will include
the contentpostcontent
: A block that appears after the main content of the page. Often used tofooter
: A block to contain your site's footer links and blanket copyrightbootstrap_js
: Loads the Bootstrap JS bundle. Override if needed.extra_js
: A block just before the closing body tag. Use this to include deferredCommon Content ships with several partial templates that can be included as the content
of the base blocks to construct a page quickly from reusable modules. These can be
loaded from the commoncontent/blocks/
template directory.
NOTE: Although the Common Content base template is an excellent starter, these block templates are very basic. This is an area for future expansion. For now, they are usable, but you probably will want to build your own.
The available block templates are:
article_list_album.html
: Displays Articles' image, title, and description as anarticle_list_blog.html
: Displays Articles' title and excerpt in a news feed style,article_text.html
: Displays the title, featured image, and full text of an Article.author_list_album.html
: Displays a profile image and short bio for each author. Usedauthor_profile.html
: Displays the author profile photo and full bio. Used on theempty.html
: An empty template to leave a block empty.footer_simple.html
: A very simple footer.header_simple.html
: A very simple header.We depend on django-sitevars for storing
site-specific variables or chunks of content. You can also store any variable for use
with your own templates. Variable can be injected into template contexts using the
context processor in sitevars.context_processors.inject_sitevars
, or using the
{% sitevar "name" %}
template tag. Variables used by the default templates/models are
listed below. Defaults for these variables are injected in the template contexts by
commoncontent.apps.context_defaults
.
base_template
- The base template to use for generic pages. Defaults tocommoncontent/base.html
.brand
- Site's brand name. Uses site.name
if not set.copyright_holder
- Custom name for the copyright holder if using the defaultsite.name
if not provided.copyright_notice
- Text to include in the copyright notice section of the footercustom_stylesheet
- A site-specific CSS file. This is pulled into the extra_head
{% static custom_stylesheet %}
so the value should be relative to the STATIC_ROOT.default_icon
- Name of a Bootstrap icon to use by default if the object providesdetail_precontent_template
- Default template to use for the precontent
block fordetail_content_template
- Default template to use for the content
block for detaildetail_postcontent_template
- Default template to use for the postcontent
blockfooter_template
- Default template to use for the footer
block.header_template
- Default template to use for the header
block.list_postcontent_template
- Default template to use for the postcontent
block forlist_precontent_template
- Default template to use for the precontent
block forlist_content_template
- Default template to use for the content
block for listpaginate_by
- Items per page on list pages, same as Django's ListView, seepaginate_orphans
- Same as Django's ListView, seeCommon Content takes advantage of django-imagekit to manage images. Models are provided for storing file metadata including copyright information.
Common Content uses presets to produce images in specific sizes as recommended by Buffer's Social Media Image Guidelines.
These named image presets are available: