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)
相关推荐
m***923817 小时前
【MySQL】C# 连接MySQL
数据库·mysql·c#
u***284717 小时前
SpringBoot集成Flink-CDC,实现对数据库数据的监听
数据库·spring boot·flink
m***119017 小时前
Ubuntu 系统下安装 Nginx
数据库·nginx·ubuntu
e***985717 小时前
Window下Redis的安装和部署详细图文教程(Redis的安装和可视化工具的使用)
数据库·redis·缓存
xingyue_S17 小时前
MySQL 数据库(一) -- 初体验
数据库·mysql·oracle
X***C86217 小时前
【Oracle11g SQL详解】UPDATE 和 DELETE 操作的正确使用
数据库·sql
爬山算法17 小时前
Redis(156)Redis的延迟问题如何解决?
数据库·redis·缓存
v***913017 小时前
Windows版Redis本地后台启动
数据库·windows·redis
x***440117 小时前
【prometheus】监控MySQL并实现可视化
数据库·mysql·prometheus
h***047717 小时前
MySQL 的 INSERT(插入数据)详解
android·数据库·mysql