Django CMS

Django is one of the most popular open-source Python web development framework. Developers use Django to build a website from scratch. Like WordPress, Django CMS is also a Content Management System that allows the developer to customize the content from the front without opening an admin page. It is written in Django language framework with Python. Django CMS 1.0 was created by Thomas Steinacher, while Django CMS 2.0 was a complete rewrite of the system by Patrick Lauber. The administration interface supports several languages.

It has a lightweight core, which makes it easier to integrate with other software. Other existing Django applications can be integrated with Django CMS or whole new applications compatible with taking advantage of CMS's features. Its user-friendly and easy drag and drop interface makes it the go-to choice for content managers, editors, and website admins. It supports multilingual publishing by default.

Features of Django CMS

  1. Frontend Editing: Edit items directly from the frontend by double click
  2. Reusable Plugins: Django CMS plugins can be used in our apps
  3. Scalable: As the documents are organized in a tree structure, it is easy to add new nodes and integrate a Django app in the tree
  4. Editorial Workflow: An organized flow for publishing and approving the website
  5. Versioning: Each modification will create a new version of the application, letting you undo changes and trace back to older versions.
  6. Multisites: Administer multiple websites from a single admin interface.
  7. Multilanguage: It publishes the website in different languages by default, making it more internationalization.
  8. Extensive Integration: The Django CMS apps can be easily integrated with other Django applications
  9. Mature: Django CMS can be used to create large projects.
  10. Extensible: The Django applications support a wide range of plugins and can itself be used as a plugin for other Django applications.
  11. Media Asset Management: Manage assets like Pictures, Videos, Documents, etc.
  12. Scripting API: There are several Python APIs that can be used to manipulate Django CMS content.
  13. Security Features: There are several security features like SSL, LDAP Authentication, Captcha that can be implemented using third-party tools
  14. WYSIWYG editor: What You See Is What You Get editor is a highly customizable editor where you can see how your app will look while developing it.
  15. Session Management: Generate a unique session ID and store it in the database.
  16. Permission Management (User Permission): Give different rights to different users.
  17. Versatile: Any website can be developed using Django like e-commerce, scientific website, a social media website, blog site, etc.

Disadvantages

  • Unconventional Framework:  It doesn’t have any principles
  • Not suitable for Small-Scale Projects:  It has lots of unique features and requires a lot of coding thus, developers won’t like to do a lot of coding for small projects
  • Multiple Request Issue: It can not handle multiple requests simultaneously
  • Steep Learning: It’s difficult to remember lots of built-in functionalities. Python is required to use this framework.

Websites Build

  1. E-Commerce
  2. Scientific Web System
  3. Banking Systems
  4. Directories

Installation

Step 1:

Create a virtual enviroment

>virtualenv cms
created virtual environment CPython3.9.5.final.0-64 in 8383ms
  creator CPython3Windows(dest=D:\Django\cms, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\AppData\Local\pypa\virtualenv)
    added seed packages: pip==21.1.3, setuptools==57.0.0, wheel==0.36.2
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Step 2:

Activate the environment

.\cms\Scripts\activate.bat && cd cms\




(cms) D:\Django\cms>

Step 3:

Install django-cms

>pip install django-cms




Collecting django-cms
  Downloading django_cms-3.9.0-py2.py3-none-any.whl (2.1 MB)
     ||||||||||||||||||||||||||||| 2.1 MB 3.3 MB/s
Collecting Django>=2.2
  Using cached Django-3.2.5-py3-none-any.whl (7.9 MB)
Collecting django-sekizai>=0.7
  Downloading django_sekizai-2.0.0-py3-none-any.whl (12 kB)
Collecting django-treebeard>=4.3
  Downloading django_treebeard-4.5.1-py3-none-any.whl (103 kB)
     |||||||||||||||||||||||||||||| 103 kB 51 kB/s
Collecting djangocms-admin-style>=1.2
  Downloading djangocms_admin_style-2.0.2-py3-none-any.whl (404 kB)
     |||||||||||||||||||||||||||||| 404 kB 192 kB/s
Collecting django-classy-tags>=0.7.2
  Downloading django_classy_tags-2.0.0-py3-none-any.whl (23 kB)
Collecting django-formtools>=2.1
  Downloading django_formtools-2.3-py3-none-any.whl (148 kB)
     |||||||||||||||||||||||||||||| 148 kB 819 kB/s
Collecting asgiref<4,>=3.3.2   Using cached asgiref-3.4.1-py3-none-any.whl (25 kB) Collecting pytz   Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB) Collecting sqlparse>=0.2.2   Using cached sqlparse-0.4.1-py3-none-any.whl (42 kB) Installing collected packages: sqlparse, pytz, asgiref, Django, django-classy-tags, djangocms-admin-style, django-treebeard, django-sekizai, django-formtools, django-cms Successfully installed Django-3.2.5 asgiref-3.4.1 django-classy-tags-2.0.0 django-cms-3.9.0 django-formtools-2.3 django-sekizai-2.0.0 django-treebeard-4.5.1 djangocms-admin-style-2.0.2 pytz-2021.1 sqlparse-0.4.1

Step 4:

Create a project

django-admin startproject djangocms

Step 5:

Install the following packages in the settings file under the INSTALLED_APPS variable.

INSTALLED_APPS = [
    'djangocms_admin_style'
    #default applications
    'django.contrib.sites',
    'cms',
    'menus',
    'treebeard',
]

To use django.contrib.sites package, we need to add a variable called SITE_ID and set it to 1.

Packages like cms, menus are core django-cms packages.

Treebeard manages page and plugin tree structures.

djangocms_admin_style provides easy UI for admin components.

Step 6:

Setting Languages for CMS as required to keep the website international.

LANGUAGES = [
    ('en', 'English'),
    ('de', 'German'),
]

Step 7:

The important part of an application is to apply migrations to Django CMS database like PostgreSQL, MySQL, SQLite. The operations like admin, auth, cms, contenttypes, menus, sessions, sites are performed in migrations

(cms) D:\Django\cms\djangocms>python manage.py migrate




Operations to perform:
  Apply all migrations: admin, auth, cms, contenttypes, menus, sessions, sites
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sites.0001_initial... OK
  Applying cms.0001_initial... OK
  Applying cms.0002_auto_20140816_1918... OK
  Applying cms.0003_auto_20140926_2347... OK
  Applying cms.0004_auto_20140924_1038... OK
  Applying cms.0005_auto_20140924_1039... OK
  Applying cms.0006_auto_20140924_1110... OK
  Applying cms.0007_auto_20141028_1559... OK
  Applying cms.0008_auto_20150208_2149... OK
  Applying cms.0008_auto_20150121_0059... OK
  Applying cms.0009_merge... OK
  Applying cms.0010_migrate_use_structure... OK
  Applying cms.0011_auto_20150419_1006... OK
  Applying cms.0012_auto_20150607_2207... OK
  Applying cms.0013_urlconfrevision... OK
  Applying cms.0014_auto_20160404_1908... OK
  Applying cms.0015_auto_20160421_0000... OK
  Applying cms.0016_auto_20160608_1535... OK
  Applying cms.0017_pagetype... OK
  Applying cms.0018_create_pagenode... OK
  Applying cms.0019_set_pagenode... OK
  Applying cms.0020_old_tree_cleanup... OK
  Applying cms.0021_auto_20180507_1432... OK
  Applying cms.0022_auto_20180620_1551... OK
  Applying menus.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying sites.0002_alter_domain_unique... OK

Step 8:

Create Super User.

(cms) D:\Django\cms\djangocms>python manage.py createsuperuser




Username (leave blank to use ' '): user1
Email address: [email protected]
Password:
Password (again):
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

When python manage.py createsuperuser is executed, it will ask for the username you want to give, or by default, it is the computer user . After entering the username, the email address is asked and then the password. If the password is common, it will ask if validation is to be bypassed and you want to use the password.

Step 9:

Check if all the necessary packages are installed

(cms) D:\Django\cms\djangocms>python manage.py cms check
←[1m********************************←[0m
←[1mChecking django CMS installation←[0m
←[1m********************************←[0m




←[1mSekizai←[0m
←[1m=======←[0m




  - Sekizai is not installed, could not find 'sekizai' in INSTALLED_APPS ←[31;1m[ERROR]←[0m
  - Sekizai template context processor is not installed, could not find 'sekizai.context_processors.sekizai' in TEMPLATES option context_processors ←[31;1m[ERROR]←[0m




←[1mInternationalization←[0m
←[1m====================←[0m




  - New style CMS_LANGUAGES ←[32;1m[OK]←[0m




←[1mMiddlewares←[0m
←[1m===========←[0m




  - django.middleware.locale.LocaleMiddleware middleware must be in MIDDLEWARE ←[31;1m[ERROR]←[0m
  - cms.middleware.user.CurrentUserMiddleware middleware must be in MIDDLEWARE ←[31;1m[ERROR]←[0m
  - cms.middleware.page.CurrentPageMiddleware middleware must be in MIDDLEWARE ←[31;1m[ERROR]←[0m
  - cms.middleware.toolbar.ToolbarMiddleware middleware must be in MIDDLEWARE ←[31;1m[ERROR]←[0m
  - cms.middleware.language.LanguageCookieMiddleware middleware must be in MIDDLEWARE ←[31;1m[ERROR]←[0m




←[1mContext processors←[0m
←[1m==================←[0m




  - cms.context_processors.cms_settings context processor must be in TEMPLATES option context_processors ←[31;1m[ERROR]←[0m




←[1mPlugin instances←[0m
←[1m================←[0m




  - Plugin instances of 0 types found in the database ←[32;1m[OK]←[0m




The plugins in your database are in good order ←[32;1m[OK]←[0m




←[1mPresence of "copy_relations"←[0m
←[1m============================←[0m








All plugins and page/title extensions have "copy_relations" method if needed. ←[32;1m[OK]←[0m




←[1mPlaceholderField←[0m
←[1m================←[0m




PlaceholderField configuration okay ←[32;1m[OK]←[0m




←[1mOVERALL RESULTS←[0m
←[1m===============←[0m




←[31;1m8 errors!←[0m
←[32;1m5 checks successful!←[0m




←[31;1mPlease check the errors above←[0m




CommandError:

The first error statingsekizai is not installed can be resolved by installing it in settings.py under the INSTALLED_APPS variable.

To remove the template errors, add the following in TEMPLATES in settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
#others
                'cms.context_processors.cms_settings',
                'django.template.context_processors.i18n',
                'sekizai.context_processors.sekizai',
               




            ],
        },
    },
]

To remove middleware errors, add the following in MIDDLEWARE in settings.py

MIDDLEWARE = [
    #other middlewares
    'django.middleware.locale.LocaleMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
]

After successful check the output looks like:

←[1m********************************←[0m
←[1mChecking django CMS installation←[0m
←[1m********************************←[0m




←[1mSekizai←[0m
←[1m=======←[0m




  - Sekizai is installed ←[32;1m[OK]←[0m
  - Sekizai template context processor is installed ←[32;1m[OK]←[0m




Sekizai configuration okay ←[32;1m[OK]←[0m




←[1mInternationalization←[0m
←[1m====================←[0m




  - New style CMS_LANGUAGES ←[32;1m[OK]←[0m




←[1mMiddlewares←[0m
←[1m===========←[0m








←[1mContext processors←[0m
←[1m==================←[0m








←[1mPlugin instances←[0m
←[1m================←[0m




  - Plugin instances of 0 types found in the database ←[32;1m[OK]←[0m




The plugins in your database are in good order ←[32;1m[OK]←[0m




←[1mPresence of "copy_relations"←[0m
←[1m============================←[0m








All plugins and page/title extensions have "copy_relations" method if needed. ←[32;1m[OK]←[0m




←[1mPlaceholderField←[0m
←[1m================←[0m








PlaceholderField configuration okay ←[32;1m[OK]←[0m








←[1mOVERALL RESULTS←[0m
←[1m===============←[0m




←[32;1m8 checks successful!←[0m




←[32;1mInstallation okay←[0m

Now, we are ready to create our CMS project.