Django CMS 的 Demo

以下是关于 Django CMS 的 Demo 示例及相关资源的整理

安装与运行 Django CMS 示例

使用 djangocms-installer 快速创建 Django CMS 项目:

复制代码
pip install django_cms
djangocms -p . mysite

安装记录

复制代码
pip install django-cms
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting django-cms
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/df/af8e6fc7eb9b6e13cbaa99b9d720e4898e9bbf75921df8b4622af03b2f21/django_cms-5.0.1-py2.py3-none-any.whl (2.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.9/2.9 MB 12.9 MB/s eta 0:00:00
Requirement already satisfied: Django>=2.2 in f:\work\pandasexample\.venv\lib\site-packages (from django-cms) (5.2.2)
Collecting django-classy-tags>=0.7.2 (from django-cms)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/10/13afc12b7d9657ed67f8d49c1cf0585a4331b197ed98ea654e9ed8034e79/django_classy_tags-4.1.0-py3-none-any.whl (14 kB)
Collecting django-formtools>=2.1 (from django-cms)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/12/63/91a107e3aaaf3987bad036494dfd8cc2675f4a66d22e65ffd6711f84ba70/django_formtools-2.5.1-py3-none-any.whl (170 kB)
Collecting django-treebeard>=4.3 (from django-cms)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/87/79/259966820614746cc4d81762edf97a53bf1e3b8e74797c010d310c6f4a8f/django_treebeard-4.7.1-py3-none-any.whl (93 kB)
Collecting django-sekizai>=0.7 (from django-cms)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c9/4f/8d1df68be504d7664cdeae7279134e77cf15babe2a5911b50f3e31d493f2/django_sekizai-4.1.0-py3-none-any.whl (8.6 kB)
Collecting djangocms-admin-style>=1.2 (from django-cms)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a6/f2/e0ed0cf8036708f7b7a26a4586a27b5e53891cf8d965f1e4751bf4f50de3/djangocms_admin_style-3.3.1-py3-none-any.whl (408 kB)
Requirement already satisfied: packaging in f:\work\pandasexample\.venv\lib\site-packages (from django-cms) (25.0)
Requirement already satisfied: setuptools in f:\work\pandasexample\.venv\lib\site-packages (from django-cms) (78.1.0)
Requirement already satisfied: asgiref>=3.8.1 in f:\work\pandasexample\.venv\lib\site-packages (from Django>=2.2->django-cms) (3.8.1)
Requirement already satisfied: sqlparse>=0.3.1 in f:\work\pandasexample\.venv\lib\site-packages (from Django>=2.2->django-cms) (0.5.3)
Requirement already satisfied: tzdata in f:\work\pandasexample\.venv\lib\site-packages (from Django>=2.2->django-cms) (2025.2)
Installing collected packages: djangocms-admin-style, django-treebeard, django-formtools, django-classy-tags, django-sekizai, django-cms
Successfully installed django-classy-tags-4.1.0 django-cms-5.0.1 django-formtools-2.5.1 django-sekizai-4.1.0 django-treebeard-4.7.1 djangocms-admin-style-3.3.1

[notice] A new release of pip is available: 25.0.1 -> 25.1.1
[notice] To update, run: python.exe -m pip install --upgrade pip

(.venv) F:\work\PandasExample>djangocms cmssite 

Clone template using django-admin
django-admin startproject "cmssite" --template https://github.com/django-cms/cms-template/archive/5.0.tar.gz
CommandError: couldn't download URL https://github.com/django-cms/cms-template/archive/5.0.tar.gz to 5.0.tar.gz: <urlopen error [Errno 11001] getaddrinfo failed>

(.venv) F:\work\PandasExample>djangocms mysite  

Clone template using django-admin
django-admin startproject "mysite" --template https://github.com/django-cms/cms-template/archive/5.0.tar.gz
cd "F:\work\PandasExample\mysite"

Install requirements in F:\work\PandasExample\mysite\requirements.in
python -m pip install -r "F:\work\PandasExample\mysite\requirements.in"

Run migrations
python -m manage migrate

Create superuser
python -m manage createsuperuser
Username (leave blank to use 'keny'): admin
Email address: [email protected]
Password: 
Password (again):
The password is too similar to the username.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

Check installation
python -m manage cms check

***************************************
django CMS 5.0.1 installed successfully
***************************************

Congratulations! You have successfully installed django CMS,
the lean enterprise content management powered by Django!

Now, to start the development server first go to your newly
created project and then call the runserver management command:
$ cd F:\work\PandasExample\mysite
$ python -m manage runserver

Learn more at https://docs.django-cms.org/
Join the django CMS Discord Server at https://discord-main-channel.django-cms.org

Enjoy!

此命令会生成一个包含基础配置的 Django CMS 项目。

目录结构
关键配置项

settings.py 中确保包含以下配置:

python 复制代码
INSTALLED_APPS = [
    'djangocms_simple_admin_style',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
     # CMS base apps
    'cms',
    'menus',

    'djangocms_text',
    'djangocms_link',
    'djangocms_alias',
    'djangocms_versioning',

    'sekizai',
    'treebeard',
    'parler',

    'filer',
    'easy_thumbnails',
    'djangocms_frontend',
    'djangocms_frontend.contrib.accordion',
    'djangocms_frontend.contrib.alert',
    'djangocms_frontend.contrib.badge',
    'djangocms_frontend.contrib.card',
    'djangocms_frontend.contrib.carousel',
    'djangocms_frontend.contrib.collapse',
    'djangocms_frontend.contrib.content',
    'djangocms_frontend.contrib.grid',
    'djangocms_frontend.contrib.icon',
    'djangocms_frontend.contrib.image',
    'djangocms_frontend.contrib.jumbotron',
    'djangocms_frontend.contrib.link',
    'djangocms_frontend.contrib.listgroup',
    'djangocms_frontend.contrib.media',
    'djangocms_frontend.contrib.navigation',
    'djangocms_frontend.contrib.tabs',
    'djangocms_frontend.contrib.utilities',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
]
urls.py
python 复制代码
urlpatterns = i18n_patterns(
    path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
    path('admin/', admin.site.urls),
    path('filer/', include('filer.urls')),
    path('', include('cms.urls')),
)

基础模板示例

在 Django CMS 中创建一个简单页面模板:

复制代码
<!-- templates/base.html -->
{% load cms_tags %}
<html>
<head>
    <title>{% page_attribute "page_title" %}</title>
</head>
<body>
    {% placeholder "content" %}
    {% static_placeholder "footer" %}
</body>
</html>

自定义插件开发

创建简单的文本插件示例:

复制代码
# cms_plugins.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _

class TextPlugin(CMSPluginBase):
    name = _("Text Plugin")
    render_template = "text_plugin.html"

plugin_pool.register_plugin(TextPlugin)

第一次运行

cd mysite

python -m manage runserver

djangocms首页

创建首页

进行首demo)
相关推荐
想用offer打牌11 分钟前
面试官问:Redis和MySQL数据一致,为什么还需要MySQL?🤠
数据库·redis·mysql
chen.@-@29 分钟前
后端下载限速(redis记录实时并发,bucket4j动态限速)
数据库·redis·缓存
王小小鸭40 分钟前
【Oracle APEX开发小技巧12】
数据库·oracle
噼里啪啦啦.1 小时前
Spring事务和事务传播机制
数据库·sql·spring
搬码红绿灯1 小时前
MySQL主从复制深度解析:原理、架构与实战部署指南
数据库·mysql·架构
呼拉拉呼拉1 小时前
Redis高可用架构
数据库·redis·架构·高可用架构
却尘1 小时前
当全世界都在用 Rust 重写一切时,Prisma 却选择了反方向
前端·数据库·orm
藥瓿锻1 小时前
2024 CKA题库+详尽解析| 15、备份还原Etcd
linux·运维·数据库·docker·容器·kubernetes·cka
远方16091 小时前
16-Oracle 23 ai-JSON-Relational Duality-知识准备
数据库·oracle·json
Wooden-Flute1 小时前
七、数据库的完整性
数据库·oracle