Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Chematronix Chematronix commented Sep 30, 2017

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

This comment has been minimized.

Copy link

@Nocks 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
You can’t perform that action at this time.