django CMS for Editors

Intro & Documentation

Before you post questions please make sure that you’ve read through the django CMS resources first:

The django CMS Admin Interface – First Steps

  • Admin Panel: The admin panel is where all functionality is accessible, it’s your starting point. You can always go to the admin panel by appending /admin to your domain (i.e. or
  • Editing a page: You can go into Edit Mode on any page, by simply adding ?edit to any URL in the browser’s address bar. So if you are on then you can append ?edit to the URL ( and hit enter. You will then see a login screen unless you are already logged in and after that be able to double click on any part of the page to edit it directly.

Editor Best Practises

Setting up a Reverse Proxy for Divio vanity media domains

There is some official documentation available at – follow those steps. Then you can change the template project as follows:

Create a default.conf file in the root of the media proxy project and copy and paste the below, replace the divio project name:

# Test this config like this: nginx -t -c /etc/nginx/nginx.conf

# Production
server {
    # divio sends all traffic to port 80 as HTTPS is terminated already at the load balancer
    listen 80;


    client_max_body_size 20M;

    if ($http_x_forwarded_proto != 'https') {
        return 301 https://$host$request_uri;

    location / {
      # for use with ssh port forwarding on the web proxy

      # for use with ssh port forwarding
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_connect_timeout 5s;


# Testing
# this runs on

# locally, test this with curl -H "X-Forwarded-Proto: https"

server {
    # divio sends all traffic to port 80 as HTTPS is terminated already at the load balancer
    listen 80 default_server;

    # catch all including local test and dev env
    server_name _ ~^(.+)$;

    client_max_body_size 20M;

    if ($http_x_forwarded_proto != 'https') {
        return 301 https://$host$request_uri;

    location / {

      proxy_ssl_protocols TLSv1.2;
      proxy_ssl_server_name on;  # prevent SSL_do_handshake() failed


      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_connect_timeout 5s;

    # Character set
    charset utf-8;

    # Logging
    access_log /var/log/nginx/access-default-site.log;
    error_log /var/log/nginx/error-default-site.log error;


Add the following to your Dockerfile:

COPY default.conf /etc/nginx/conf.d/default.conf

Deploy this and check if it works. You can get the DSN by logging into your main project via SSH and then execute echo $DEFAULT_STORAGE_DSN , then take that value, update the domain value and add the new DSN to the divio env vars.

deploy a production-ready React app on (HTTP to HTTPS Redirect on nginx)

The problem: Cloud hosting services such as terminate HTTPS already at the loadbalancer level. Your container that hosts react will never receive an incoming HTTPS connection. Still, upgrading HTTP connections to HTTPS connections falls in the responsibility of your container. How to fix that?

Special thanks to Jonathan for his advice and support.

Here is how to build and serve a React app with nginx on

Add an nginx/default.conf to your project:

## Redirect HTTP to HTTPS

server {
    # divio sends all traffic to port 80 as HTTPS is terminated already at the load balancer
    listen 80;

    client_max_body_size 20M;

    if ($http_x_forwarded_proto != 'https') {
        return 301 https://$host$request_uri;

    location / {
      alias /usr/share/nginx/html/;
      try_files $uri $uri/ /index.html =404;


change your Dockerfile accordingly:

FROM node:12.16.1 as builder

# for caching optimisations
COPY package*.json /
RUN npm install

COPY . /app

ENV PATH=/node_modules/.bin:$PATH

RUN npm run build

FROM nginx:latest
COPY --from=builder /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/default.conf /etc/nginx/conf.d

CMD ["nginx", "-g", "daemon off;"]

Update your docker-compose.yml for local support and testing (optional):

# This docker-compose.yml file is used to set up your project in the local
# development environment *only*. It is *not* used in deployment to our cloud
# servers, and has no effect whatsoever in cloud deployments.
# See our Developer Handbook for more information:
version: "2.3"

  # The web container is an instance of exactly the same Docker image as your
  # Cloud application container.
      context: .
      target: builder
    # Change the port if you'd like to expose your project locally on a
    # different port, for example if you already use port 8000 for
    # something else.
     - "8000:80"
      - ".:/app:rw"
    # There is currently a bug:
    tty: true
    # The default command that the container starts with. If you'd like to run
    # the project locally in Live configuration, you will need to change this.
    # See
    command: npm start

    build: .
    # Change the port if you'd like to expose your project locally on a
    # different port, for example if you already use port 8000 for
    # something else.
     - "8000:80"
      - "./nginx/default.conf:/etc/nginx/conf.d/default.conf"
    command: [nginx-debug, '-g', 'daemon off;']

Working with videos in Content Management Systems (CMS)

There are a few things to know when handling videos in Content Management Systems (CMS). Are you set to become a pro CMS editor? Then please read on:

Video Hosting

You might not be aware, but CMS are not a great place to host video. CMS run on web hosting, which is in most cases not suitable for hosting of large files. Also consider that the video file (for example an .mp4 video format) that you have locally on your desktop might not be optimized for the web.

On the other hand, video platforms such as youtube or vimeo have specialized in video hosting. Videos uploaded on video platforms are auto-magically compressed and optimized for the web, for the maximum compatibility! Doesn’t that sound like the right choice for hosting videos!

Good to know: Platforms such as youtube allow you to host videos for your website without showing them anywhere else, for example your youtube channel. This special mode is called an “unlisted” video.

Now how do we get Youtube play nicely together with your CMS? You have probably already seen that the video component in your CMS allows to insert a Youtube link. Let’s go get that link on youtube!

Step 1: Create an “unlisted” video on Youtube

Go to – if you don’t have a Google Account, maybe now is a good time to set up a shared gmail address for your department or team. Make sure you select the right channel or create a new one. Since it won’t be public anyway, you dont need to upload a logo or care about any optional fields. Then at some point you can upload your video:

Here you can just drag and drop your video
Set the visibility to “unlisted”
click on the link after the video has finished processing
copy the first part of the video url from the browser address bar (without &

Step 2: Edit the page in the CMS where you would like to add the video, add a video component

This is how it looks in django CMS:

simply paste the link from youtube into your CMS video component. In django CMS it’s called video player and the field is situated in the Embed video section.

Once you save, you can now see your video nicely embedded on your page!

Pro Tipp for Youtube

Did you notice the small video thumbnails that youtube puts at the end of your video to keep the user engaged? This is often not desirable. You can limit those previews to show only other (public) videos from your channel. In django CMS’ video component this behaviour can be configured with the Parameters field right below the video URL field. Just hit the + button and set a parameter rel to the value 0. In other systems you can try appending &rel=0 to the video URL. Try this example:

Working with images in Content Management Systems

There are a few things to know when handling images in Content Management Systems (CMS). Are you set to become a pro CMS editor? Then please read on:

Image size

We get it – you would like to have high quality images / photos everywhere on your website! We do, too! However bigger is not always better. It’s also important to optimize for page speed (see here why pagespeed matters). This means that the file size of our pictures should be as small as possible, while, of course, keeping the image quality on a satisfactory level.

Here is how!

Compress your Image

Some CMS compress images automatically when you upload it – but often the built-in image compression is not what it could be. On top of that, many CMS will keep the original image anyway “for the record”, using up unnecessary disk space.

It’s therefore recommendable to first upload your images to a tool such as – Here you can safely assume that your images are compressed to the max!

Just drag and drop your image(s) here!

Resize your image

Once you compressed your images, you can make your image even smaller by clicking the resize button right where you are!

After compressing, click the resize button

These days, images are best resized to either width or height at or below 4,000px (the most recent TV screens are called Ultra HD and have a 4K image resolution (3,840 x 2,160 pixels) and the most recent Macbook Air (3rd gen) has a screen resolution of  2,560 x 1,600 pixel.

If you know that your image won’t cover the full screen, you can resize it to something even smaller, for example max 500px (either width or height).

Enter a number for either height or width that is lower than the pre-filled value and press “Resize Images”

Image naming

Now you have a perfectly optimized image! Even though some CMS allow you to change the file name later on, the original file name will still be stored and will linger around! It is therefore recommended to give the image a speaking file name before you upload it to the CMS.

Good Example ✅: woman-in-green-dress-pointing-at-screen.jpg

  • Try to avoid spaces, use hyphens (the minus character) instead
  • try to describe what’s on the picture, not what you use the picture for (bad example: ❌ product-page-first-section.jpg)
  • put your image in a folder so it’s easier for you to find it later. Example folder name: Blog Post Header Images

Now you are ready to upload your picture into the CMS! 👏 Well done! 👍

By the way: Responsive Images

Some images are treated in a “smart” way by the CMS, meaning that the CMS adapts the width of the image according to the window width, and keeps the height of the image at an acceptable value according to the device or window width. Sounds like magic? It is!

Please read on about responsive images here:

Wichtige Punkte eines Website Relaunch Briefings

Welche Punkte müssen Teil eines Website Relaunch Briefings sein?

Konzeption, UX & Design

  • Branding, CI / CD: Branding Book, Style Guide, Webfonts, Ikonographie, etc. als Input für Web Design
  • Fotografie: authentisches Fotomaterial, z.B. Portraits, Team-Bilder, etc.
  • Illustrationen: optional, ggf in Budget einplanen
  • Informations-Architektur (IA) & Inhalte: Welche Seiten, welche Hierarchien? Testimonials, Services, Produkte, Projekte, Team, Kontakt, Jobs, Blog, Landing Pages, etc.
  • Web Design: Gestaltung von einzelnen Schlüssel-Seiten durch einen professionellen Web Designer in hoher Detailtreue in XD, Sketch oder figma, als pixel-genaue Vorlage für die Umsetzung.


  • Content Migration: Content Management Ressourcen bereitstellen, bzw. im Budget einplanen.
  • Copywriting: Ressourcen bereitstellen für das Copywriting falls nötig, bzw. im Budget einplanen.
  • Übersetzungen & Mehrsprachigkeit: Welche Sprachen sind relevant? Für Übersetzungen ggf Ressourcen bereitstellen oder in Budget einplanen

Online Marketing

  • Suchmaschinen-Sichtbarkeit: technisches SEO, Redirects setzen, Search Console und langfristige SEO-Strategie
  • Conversion Tracking & Analytics: Google Analytics migrieren, Google Tag Manager aufsetzen, Conversion Ziele (z.B. Whitepaper Download) festlegen und Tracking aufsetzen.
  • UX & Conversion Rate Optimierung: Geeignete Call-to-Actions setzen, Optimierung der User Experience (UX)
  • Performance: Page Speed Optimierung, Server Caching, Browser Caching Settings optimieren
  • Content Strategy: Relevante Themenwelten bestimmen
  • CRM Integration: Hubspot Formulare & Tracking aufsetzen.

Technologie & Operations

  • Content Management System & Technologie Stack: Gibt es CMS- oder sogar Technologie-Präferenzen (z.B. python / django oder PHP)? Sind die Inhalts-Editoren bereits mit einem System vertraut? Sind Applikations-Logiken (z.B. ein Kundenportal) oder Integrationen mit anderen Systemen (z.B. SAP, ein DAM- oder PIM-System) geplant?
  • Device & browser Kompatibilität: Kompatibilitäts-Matrix festlegen gemäss Google Analytics Auswertung: Welche Browser & Geräte sind besonders relevant? IE11 Kompatibilität noch notwendig? Ggf im Budget entsprechend einplanen.
  • Hosting, Maintenance & Security: Sicherstellen performantes Hosting, Service Level Agreement inkl Backup und Maintenance Konditionen.

Rechtliche Aspekte

Privacy / GDPR: Muss den Usern die Möglichkeit zur vollen Datenschutz-Verwaltung gegeben werden gemäss EU-Richtlinie? Oder reicht eine abgespeckte Schweizer Lösung, z.B. Marketing cookies / scripts nur aktiv nach Opt-in des Users und Google Analytics standardmässig aktiv mit Möglichkeit zum Opt-out.

floating labels for bootstrap 4 forms

based on

Bootstrap 4 form row:

<div class="row">
    <div class="col">
        <div class="form-group">
            <label class="has-float-label">
                <input class="form-control" name="email" type="text" placeholder="E-Mail" class="is-invalid">
            <p class="invalid-feedback d-block">
                This is a validation error message that needs to be inserted dynamically

SCSS mixin:

@import "~bootstrap/scss/functions/";
@import "~bootstrap/scss/mixins/";
@import "~bootstrap/scss/variables/";

@mixin has-float-label {
// taken from
display: block;
position: relative;

label, & > span {
background: white;
position: absolute;
cursor: text;
font-size: 75%;
opacity: 1;
-webkit-transition: all .2s;
transition: all .2s;
top: -.5em;
left: 0.75rem;
z-index: 3;
line-height: 1;
padding: 0 2px;

.form-control {

&::placeholder {
opacity: 0;
transition: all .2s;

&:placeholder-shown:not(:focus) + * {
font-size: 100%;
color: $input-placeholder-color;
transform: translateY(-50%);
top: 50%;


always freeze requirements with pip-compile to avoid unpleasant surprises

Have you ever been in a situation, where you wanted to setup a project you haven’t been working on for a while and it failed with a cryptic error for no apparent reason?

Chances are that you didn’t freeze your requirements and one of the new packages you just installed got upgraded and the new code is incompatible with your codebase and this causes a random error!

This could be avoided by freezing requirements.txt after the initial development phase of a project. This solution however prevents an efficient upgrade process later on. What would an efficient dependency upgrade process look like?

  • Unfreeze all dependencies
  • run pip install –upgrade on all dependencies
  • test the project, if there are problems, find and downgrade the problematic package or upgrade the project’s code. If everything is ok, go to next step
  • freeze all dependencies again, check changes into source control and deploy.

Enters pip-tools with pip-compile!

pip-compile does exactly that. In order to be able to easily upgrade all packages, pip-compile works with two separate files.

  1. It contains only the packages added by the developer. Typically, this is also the place where the developer adds comments next to a package, explaining why it is needed and describing any quirks or special information. The developer does NOT add any version numbers here, unless it’s required to make the project run (example: package-name>3.5 # doesnt work with a lower version)
  2. requirements.txt This file contains the compiled output from pip-compile including any dependent packages. No manual edits should be done here, they would be overwritten upon subsequent compilation. All packages are frozen in this file (= have a version number assigned). The project uses this file to install dependencies. It’s important that this file is included in source control (git).

Pip Compile Workflow

  • the developer manages packages in – generally **without** versions
  • then create a new requirements.txt with docker-compose run --rm web pip-compile > requirements.txt
  • docker-compose exec web pip install -r requirements.txt or just simply docker-compose build web
  • Testing, QA & fixes, checking changes into source control, finally deployment

django doesnt work out of the box with multiple gunicorn/uwsgi workers 🤯

This is really incredible but django has an extremely unfortunate default CACHE setting that is not ok for production environments, it defaults to a local memory cache that is not shared between different gunicorn or uwsgi workers. As a result, each worker can have a different state, even database values might differ in a django form!

Read here and here

Solution: Set up memcached (apt get install memcached also you need to enable sockets if you want to use unix sockets, otherwise change the below config to use tcp instead) and set up django to use that cache backend in production environments:

'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'unix:/var/run/memcached/memcached.sock',

django CMS PageField

In the (it’s an extended ForeignKey field:

from cms.models.fields import PageField

faq_page_link = PageField()

How to use it in a template?

<a href="{{ instance.get_absolute_url }}">Demo Link to the FAQ Page</a>

Todo: What form widgets are available and how can they be configured on a PageField model field?