3. Configuration
The django CMS has a lot of settings you can use to customize your installation so that it is exactly as you’d like it to be.
3.1. Required Settings
3.1.1. CMS_TEMPLATES
Default: ()
(Not a valid setting!)
A list of templates you can select for a page.
Example:
CMS_TEMPLATES = (
('base.html', gettext('default')),
('2col.html', gettext('2 Column')),
('3col.html', gettext('3 Column')),
('extra.html', gettext('Some extra fancy template')),
)
Note
All templates defined in CMS_TEMPLATES
must contain at least the js
and css
sekizai namespaces, for more information, see Static files handling with sekizai.
Warning
django CMS internally relies on a number of templates to function correctly. These exist beneath cms
within the templates directory. As such, it is highly recommended you avoid using the same directory name for your own project templates.
3.2. Basic Customization
3.2.1. CMS_TEMPLATE_INHERITANCE
Default: True
Optional Enables the inheritance of templates from parent pages.
If this is enabled, pages have the additional template option to inherit their template from the nearest ancestor. New pages default to this setting if the new page is not a root page.
3.2.2. CMS_PLACEHOLDER_CONF
Default: {}
Optional
Used to configure placeholders. If not given, all plugins are available in all placeholders.
Example:
CMS_PLACEHOLDER_CONF = {
'content': {
'plugins': ['TextPlugin', 'PicturePlugin'],
'text_only_plugins': ['LinkPlugin']
'extra_context': {"width":640},
'name':gettext("Content"),
},
'right-column': {
"plugins": ['TeaserPlugin', 'LinkPlugin'],
"extra_context": {"width":280},
'name':gettext("Right Column"),
'limits': {
'global': 2,
'TeaserPlugin': 1,
'LinkPlugin': 1,
},
},
'base.html content': {
"plugins": ['TextPlugin', 'PicturePlugin', 'TeaserPlugin']
},
}
You can combine template names and placeholder names to granularly define plugins, as shown above with ‘’base.html content’‘.
plugins
A list of plugins that can be added to this placeholder. If not supplied, all plugins can be selected.
text_only_plugins
A list of additional plugins available only in the TextPlugin, these plugins can’t be added directly to this placeholder.
extra_context
Extra context that plugins in this placeholder receive.
name
The name displayed in the Django admin. With the gettext stub, the name can be internationalized.
limits
Limit the number of plugins that can be placed inside this placeholder. Dictionary keys are plugin names and the values are their respective limits. Special case: “global” - Limit the absolute number of plugins in this placeholder regardless of type (takes precedence over the type-specific limits).
3.2.3. CMS_PLUGIN_CONTEXT_PROCESSORS
Default: []
A list of plugin context processors. Plugin context processors are callables that modify all plugins’ context before rendering. See Custom Plugins for more information.
3.2.4. CMS_PLUGIN_PROCESSORS
Default: []
A list of plugin processors. Plugin processors are callables that modify all plugin’s output after rendering. See Custom Plugins for more information.
3.2.5. CMS_APPHOOKS
Default: ()
A list of import paths for cms.app_base.CMSApp
subclasses.
Defaults to an empty list which means CMS applications are auto-discovered in all INSTALLED_APPS
by trying to import their cms_app
module.
If this setting is set, the auto-discovery is disabled.
Example:
CMS_APPHOOKS = (
'myapp.cms_app.MyApp',
'otherapp.cms_app.MyFancyApp',
'sampleapp.cms_app.SampleApp',
)
3.2.6. PLACEHOLDER_FRONTEND_EDITING
Default: True
If set to False
, frontend editing is not available for models using cms.models.fields.PlaceholderField
.
3.3. Editor configuration
The Wymeditor from cms.plugins.text
plugin can take the same configuration as vanilla Wymeditor. Therefore you will need to learn how to configure that. The best thing to do is to head over to the Wymeditor examples page in order to understand how Wymeditor works.
The cms.plugins.text
plugin exposes several variables named WYM_* that correspond to the wym configuration. The simplest way to get started with this is to go to cms/plugins/text/settings.py
and copy over the WYM_* variables and you will realize they match one to one to Wymeditor’s.
Currently the following variables are available:
WYM_TOOLS
WYM_CONTAINERS
WYM_CLASSES
WYM_STYLES
WYM_STYLESHEET
3.4. I18N and L10N
3.4.1. CMS_LANGUAGES
Default: Value of LANGUAGES
converted to this format
Defines the languages available in django CMS.
Example:
CMS_LANGUAGES = {
1: [
{
'code': 'en',
'name': gettext('English'),
'fallbacks': ['de', 'fr'],
'public': True,
'hide_untranslated': True,
'redirect_on_fallback':False,
},
{
'code': 'de',
'name': gettext('Deutsch'),
'fallbacks': ['en', 'fr'],
'public': True,
},
{
'code': 'fr',
'name': gettext('French'),
'public': False,
},
],
2: [
{
'code': 'nl',
'name': gettext('Dutch'),
'public': True,
'fallbacks': ['en'],
},
],
'default': {
'fallbacks': ['en', 'de', 'fr'],
'redirect_on_fallback':True,
'public': False,
'hide_untranslated': False,
}
}
Note
Make sure you only define languages which are also in LANGUAGES
.
CMS_LANGUAGES has different options where you can granular define how different languages behave.
On the first level you can define SITE_IDs and default values. In the example above we define two sites. The first site has 3 languages (English, German and French) and the second site has only Dutch. The default node defines default behavior for all languages. You can overwrite the default settings with language specific properties. For example we define hide_untranslated as False globally. The English language overwrites this behavior.
Every language node needs at least a code and a name property. code is the iso 2 code for the language. And name is the verbose name of the language.
Note
With a gettext() lambda function you can make language names translatable. To enable this add gettext = lambda s: s at the beginning of your settings file. But maybe you want to leave the language name as it is.
What are the properties a language node can have?
3.4.1.1. code
String. RFC5646 code of the language.
Example: "en"
.
Note
Is required for every language.
3.4.1.2. name
String. The verbose name of the language.
Note
Is required for every language.
3.4.1.3. public
Is this language accessible in the frontend? For example, if you decide you want to add a new language to your page but don’t want to show it to the world yet.
Type: Boolean Default: True
3.4.1.4. fallbacks
A list of languages that are used if a page is not translated yet. The ordering is relevant.
Example: ['de', 'fr']
Default: []
3.4.1.5. hide_untranslated
Should untranslated pages be hidden in the menu?
Type: Boolean Default: True
3.4.1.6. redirect_on_fallback
If a page is not available should there be a redirect to a language that is, or should the content be displayed in the other language in this page?
Type: Boolean Default:True
3.4.2. Unicode support for automated slugs
The django CMS supports automated slug generation from page titles that contain unicode characters via the unihandecode.js project. To enable support for unihandecode.js, at least CMS_UNIHANDECODE_HOST
and CMS_UNIHANDECODE_VERSION
must be set.
3.4.2.1. CMS_UNIHANDECODE_HOST
default: None
Must be set to the URL where you host your unihandecode.js files. For licensing reasons, the django CMS does not include unihandecode.js.
If set to None
, the default, unihandecode.js is not used.
Note
Unihandecode.js is a rather large library, especially when loading support for Japanese. It is therefore very important that you serve it from a server that supports gzip compression. Further, make sure that those files can be cached by the browser for a very long period.
3.4.2.2. CMS_UNIHANDECODE_VERSION
default: None
Must be set to the version number (eg '1.0.0'
) you want to use. Together with CMS_UNIHANDECODE_HOST
this setting is used to build the full URLs for the javascript files. URLs are built like this: <CMS_UNIHANDECODE_HOST>-<CMS_UNIHANDECODE_VERSION>.<DECODER>.min.js
.
3.4.2.3. CMS_UNIHANDECODE_DECODERS
default: ['ja', 'zh', 'vn', 'kr', 'diacritic']
If you add additional decoders to your CMS_UNIHANDECODE_HOST`
, you can add them to this setting.
3.4.2.4. CMS_UNIHANDECODE_DEFAULT_DECODER
default: 'diacritic'
The default decoder to use when unihandecode.js support is enabled, but the current language does not provide a specific decoder in CMS_UNIHANDECODE_DECODERS
. If set to None
, failing to find a specific decoder will disable unihandecode.js for this language.
3.5. Media Settings
3.5.1. CMS_MEDIA_PATH
default: cms/
The path from MEDIA_ROOT
to the media files located in cms/media/
3.5.2. CMS_MEDIA_ROOT
Default: MEDIA_ROOT
+ CMS_MEDIA_PATH
The path to the media root of the cms media files.
3.5.3. CMS_MEDIA_URL
default: MEDIA_URL
+ CMS_MEDIA_PATH
The location of the media files that are located in cms/media/cms/
3.5.4. CMS_PAGE_MEDIA_PATH
Default: 'cms_page_media/'
By default, django CMS creates a folder called cms_page_media
in your static files folder where all uploaded media files are stored. The media files are stored in subfolders numbered with the id of the page.
You should take care that the directory to which it points is writable by the user under which Django will be running.
3.6. URLs
3.6.1. CMS_URL_OVERWRITE
Default: True
This adds a new field “url overwrite” to the “advanced settings” tab of your page. With this field you can overwrite the whole relative url of the page.
3.6.2. CMS_MENU_TITLE_OVERWRITE
Default: False
This adds a new “menu title” field beside the title field.
With this field you can overwrite the title that is displayed in the menu.
To access the menu title in the template, use:
{{ page.get_menu_title }}
3.6.3. CMS_REDIRECTS
Default: False
This adds a new “redirect” field to the “advanced settings” tab of the page.
You can set a url here to which visitors will be redirected when the page is accessed.
Note: Don’t use this too much. django.contrib.redirects
is much more flexible, handy, and is designed exactly for this purpose.
3.6.4. CMS_SOFTROOT
Default: False
This adds a new “softroot” field to the “advanced settings” tab of the page. If a page is marked as softroot the menu will only display items until it finds the softroot.
If you have a huge site you can easily partition the menu with this.
3.7. Advanced Settings
3.7.1. CSRF_COOKIE_NAME
In case you’ve overwritten the default Django CSRF_COOKIE_NAME setting, then you should inform Django-CMS about this by using a context processor dedicated for this. Extend the list of TEMPLATE_CONTEXT_PROCESSORS with
'cms.context_processors.csrf_cookie_name',
3.7.2. CMS_PERMISSION
Default: False
If this is enabled you get 3 new models in Admin:
- Pages global permissions
- User groups - page
- Users - page
In the edit-view of the pages you can now assign users to pages and grant them permissions. In the global permissions you can set the permissions for users globally.
If a user has the right to create new users he can now do so in the “Users - page”. But he will only see the users he created. The users he created can also only inherit the rights he has. So if he only has been granted the right to edit a certain page all users he creates can, in turn, only edit this page. Naturally he can limit the rights of the users he creates even further, allowing them to see only a subset of the pages to which he is allowed access.
3.7.3. CMS_RAW_ID_USERS
Default: False
This setting only applies if CMS_PERMISSION
is True
The “view restrictions” and “page permissions” inlines on the cms.models.Page
admin change forms can cause performance problems where there are many thousands of users being put into simple select boxes. If set to a positive integer, this setting forces the inlines on that page to use standard Django admin raw ID widgets rather than select boxes if the number of users in the system is greater than that number, dramatically improving performance.
Note
Using raw ID fields in combination with limit_choices_to
causes errors due to excessively long URLs if you have many thousands of users (the PKs are all included in the URL of the popup window). For this reason, we only apply this limit if the number of users is relatively small (fewer than 500). If the number of users we need to limit to is greater than that, we use the usual input field instead unless the user is a CMS superuser, in which case we bypass the limit. Unfortunately, this means that non-superusers won’t see any benefit from this setting.
3.7.4. CMS_PUBLIC_FOR
Default: all
Decides if pages without any view restrictions are public by default or staff only. Possible values are all
and staff
.
3.7.5. CMS_SHOW_START_DATE & CMS_SHOW_END_DATE
Default: False
for both
This adds two new DateTimeField
fields in the “advanced settings” tab of the page. With this option you can limit the time a page is published.
3.7.6. CMS_SEO_FIELDS
Default: False
This adds a new “SEO Fields” fieldset to the page admin. You can set the Page Title, Meta Keywords and Meta Description in there.
To access these fields in the template use:
{% load cms_tags %}
<head>
<title>{% page_attribute page_title %}</title>
<meta name="description" content="{% page_attribute meta_description %}"/>
<meta name="keywords" content="{% page_attribute meta_keywords %}"/>
...
...
</head>
3.7.7. CMS_CACHE_DURATIONS
This dictionary carries the various cache duration settings.
3.7.7.1. 'content'
Default: 60
Cache expiration (in seconds) for show_placeholder
and page_url
template tags.
Note
This settings was previously called CMS_CONTENT_CACHE_DURATION
3.7.7.2. 'menus'
Default: 3600
Cache expiration (in seconds) for the menu tree.
Note
This settings was previously called MENU_CACHE_DURATION
3.7.7.3. 'permissions'
Default: 3600
Cache expiration (in seconds) for view and other permissions.
3.7.8. CMS_CACHE_PREFIX
Default: cms-
The CMS will prepend the value associated with this key to every cache access (set and get). This is useful when you have several django CMS installations, and you don’t want them to share cache objects.
Example:
CMS_CACHE_PREFIX = 'mysite-live'
Note
Django 1.3 introduced a site-wide cache key prefix. See Django’s own docs on cache key prefixing
3.7.9. CMS_MAX_PAGE_PUBLISH_REVERSIONS
Default: 25
If django-reversion is installed everything you do with a page and all plugin changes will be saved in a revision. In the page admin there is a history button to revert to previous version of a page. In the past we had the problem with huge databases from the revision tables after some time. As a mitigation when you publish a page all revisions that are not publish revision will be deleted. This setting however declares how many publish revisions are saved in the database. By default the newest 25 publish revisions are kept and all other are deleted when you publish a page. If you set this to 0 all publish revisions are kept but you are responsible to keep the revision table small.