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)
相关推荐
Crazy________39 分钟前
13MySQL主从复制原理与搭建指南
数据库·mysql
June`1 小时前
Redis核心应用:从单机到分布式架构解析
数据库·redis·缓存
学习编程的Kitty1 小时前
MySQL——数据库基础与库的操作
数据库·mysql
krielwus1 小时前
Oracle 11g R2 物理冷备操作文档
数据库·oracle
大气层煮月亮1 小时前
Oracle EBS ERP之报表开发—嵌入Web中的报表预览、报表打印
前端·数据库·oracle
会挠头但不秃1 小时前
Redis数据结构和常用命令
数据库·redis·缓存
楠目1 小时前
SQL注入与防御:从攻击原理到预编译防御
数据库·sql
无名前端小白1 小时前
Oracle 转 PostgreSQL, ora2pg docker compose 简单实践版
数据库·postgresql·oracle
庸人自扰613 小时前
Redis从零讲解
数据库·redis·缓存
lypzcgf4 小时前
Coze源码分析-资源库-删除数据库-后端源码-领域服务/数据访问层
数据库·go·coze·coze源码分析·智能体平台·ai应用平台·agent平台