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)
相关推荐
pale_moonlight12 分钟前
五、Hbase基于环境搭建
linux·数据库·hbase
Elastic 中国社区官方博客17 分钟前
Elasticsearch:相关性在 AI 代理上下文工程中的影响
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
程序员卷卷狗25 分钟前
联合索引的最左前缀原则与失效场景
java·开发语言·数据库·mysql
蓝色猪猪侠2 小时前
postgresql数据库的安装
数据库
敖云岚2 小时前
【疑难解答】MySQL 报错 Public Key Retrieval is not allowed
数据库·mysql
小旺不正经2 小时前
Linux介绍及常用命令
linux·运维·数据库
焦糖码奇朵、3 小时前
移动通信网络建设-实验2:5G站点选型与设备部署
网络·数据库·人工智能·5g·信号处理·基带工程
l1t3 小时前
把ITPUB newkid先生编写的Oracle语法数独求解SQL改写成DuckDB
数据库·人工智能·sql·oracle·duckdb
ヾChen3 小时前
MySQL——增删改查操作
数据库·sql·物联网·学习·mysql