Skip to content

Instantly share code, notes, and snippets.

@superduper
Last active October 7, 2017 09:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superduper/adb941c3b0158c343b14d089c1f60efe to your computer and use it in GitHub Desktop.
Save superduper/adb941c3b0158c343b14d089c1f60efe to your computer and use it in GitHub Desktop.
Updating django-cms to use django 1.10

Upgrading djangocms-installer scaffolded project django version

Abstract

I used djangocms-installer to bootstrap django-cms project. Installer saves a great deal of time spent on intialization but its requirements.txt are outdated. As of Feb 15 2016 it enforces django<1.9 and other package requirements. This is because django-cms didn't officially support django>1.10 at a time last djangocms-installer version was released.

This article describes how I updated generated project to support django=>1.10.

Upgrading

  1. Update requirements.txt. Replace version for these packages:

    django-cms>=3.4.2,<3.5
    djangocms-admin-style>=1.2,<1.3
    django-treebeard>=4.0.1,<5.0
    django-formtools>=1.0
    Django>=1.10,<1.11
    django-classy-tags>=0.7.2
    django-sekizai>=0.9
    django-select2==5.8.10
    
  2. Update & migrate

    Update installed packages

    pip install --upgrade -r requirements.txt
    

    Apply migrations

    python manage.py migrate
    
  3. settings.py Replace django.core.context_processors -> django.template.context_processors in this section:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'project', 'templates'),],
            'OPTIONS': {
                'context_processors': [
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                    'django.template.context_processors.i18n',
                        'django.template.context_processors.debug',
                        'django.template.context_processors.request',
                        'django.template.context_processors.media',
                        'django.template.context_processors.csrf',
                        'django.template.context_processors.tz',
                        'sekizai.context_processors.sekizai',
                        'django.template.context_processors.static',
                        'cms.context_processors.cms_settings'
                    ],
                    'loaders': [
                        'django.template.loaders.filesystem.Loader',
                        'django.template.loaders.app_directories.Loader',
                        'django.template.loaders.eggs.Loader'
                    ],
                },
            },
        ]
    
    
  4. urls.py

    Here we replace string view import paths with views themselves(import and pass callable)

    Add imports:

    from django.contrib.sitemaps.views import sitemap
    from django.views.static import serve as static_serve
    

    Update sitemap definition

    urlpatterns = [
        url(r'^sitemap\.xml$', sitemap,
            {'sitemaps': {'cmspages': CMSSitemap}}),
    

    Remove empty string('') from i18n_patterns call:

    urlpatterns += i18n_patterns(
        url(r'^admin/', include(admin.site.urls)),  # NOQA
        url(r'^', include('cms.urls')),
    )
    

    Replace static serve import path string with view

    # This is only needed when using runserver.
    if settings.DEBUG:
        urlpatterns = [
            url(r'^media/(?P<path>.*)$', static_serve,
                {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
            ] + staticfiles_urlpatterns() + urlpatterns
    

Et voilà!

@Chematronix
Copy link

As of September 2017, you can specify which Django you want to the DjangoCMS installer, like this:

djangocms --django-version=1.10 --skip-empty-check --bootstrap yes --starting-page yes --filer --verbose --no-input --languages es,en --parent-dir . MyProject

Note that by default it will install the last Django LTS version supported by DjangoCMS (that'd be 1.8 ATM).

@Nocks
Copy link

Nocks commented Oct 7, 2017

@Chematronix Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment