Qu'est-ce ? Pourquoi ? Pour qui ? Comment ? D'où viens-je ? Où vais-je ? Qu'est-ce que je fous là ?
INSTALLED_APPS = [
'django.contrib.admin',
'cms',
]
* avec un tout petit peu de magie
LANGUAGES = (
('en', _('English')),
('fr', _('French')),
)
🦄
* mais c'est peut-être mieux comme ça
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
*clic*
clear cache
clear cache
clear cache
clear cache
clear cache
>>> drupal + sylvain TypeError: unsupported operand type(s) for +: 'cms' and 'developer'
Templates
Placeholders
Plugins
Pages
Données de plugins
* tout est relatif
Placeholder
Placeholder
Placeholder
Plugin
Plugin
Plugin
Plugin
templates/base.html
{% load cms_tags %}
<!doctype html>
<html>
<body>
<header>
<div class="header-top">{% static_placeholder "header_top" %}</div>
<div class="header-bottom">{% static_placeholder "header_bottom" %}</div>
</header>
<div class="main-content">{% placeholder "main_content" %}</div>
</body>
</html>
from django.db import models
from cms.models import CMSPlugin
class ColorBox(CMSPlugin):
COLOR_CHOICES = (
('lime', 'Lime'),
('green', 'Green'),
('yellow', 'Yellow'),
('orange', 'Orange'),
)
color = models.CharField(choices=COLOR_CHOICES, max_length=20)
title = models.CharField(max_length=255)
body = models.TextField()
def __str__(self):
return self.title
models.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .models import ColorBox
class ColorBoxPlugin(CMSPluginBase):
model = ColorBox
module = "Cruncher"
name = "Color box"
render_template = "cruncher_core/color_box.html"
plugin_pool.register_plugin(ColorBoxPlugin)
cms_plugins.py
<div class="block {{ instance.color }}-block">
<h2>{{ instance.title }}</h2>
<p>{{ instance.body }}</p>
</div>
cruncher_core/color_box.html
./manage.py runserver