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: admin@qq.com
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)
相关推荐
小糖学代码13 小时前
MySQL:14.mysql connect
android·数据库·mysql·adb
爬山算法13 小时前
Redis(69)Redis分布式锁的优点和缺点是什么?
数据库·redis·分布式
RestCloud13 小时前
从数据库到价值:ETL 工具如何打通南大通用数据库与企业应用
数据库
惜月_treasure14 小时前
Text2SQL与工作流实现:让数据库查询变得轻松又高效
数据库·人工智能·python
-睡到自然醒~14 小时前
[go 面试] 并发与数据一致性:事务的保障
数据库·面试·golang
为乐ovo14 小时前
19.DCL-用户管理
数据库
一个天蝎座 白勺 程序猿15 小时前
金仓数据库KingbaseES实现MongoDB平滑迁移全攻略:从架构适配到性能调优的完整实践
数据库·mongodb·数据迁移·kingbasees·金仓数据库
武子康15 小时前
Java-153 深入浅出 MongoDB 全面的适用场景分析与选型指南 场景应用指南
java·开发语言·数据库·mongodb·性能优化·系统架构·nosql
2401_8370885015 小时前
Redis通用命令
数据库·redis·缓存
程序边界15 小时前
MongoDB迁移到KES实战全纪录(上):迁移准备与实施指南
数据库·mongodb