【问题标题】:Django CMS - Unable to modify structure of a newly added webpageDjango CMS - 无法修改新添加网页的结构
【发布时间】:2020-10-18 20:05:51
【问题描述】:

我对 Django CMS 完全陌生,我一直被这个问题困扰。

我在现有的 Django 项目中添加了一个新模块并创建了一个新的 Html 页面。这是 settings.py

中的模板配置
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'site_cms', 'templates'),
                 ],
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.i18n',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.template.context_processors.csrf',
                'django.template.context_processors.tz',
                'sekizai.context_processors.sekizai',
                'django.template.context_processors.static',
                'cms.context_processors.cms_settings',
                'core.context_processors.request_info',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.eggs.Loader'
            ],
        },
    },
]

在新页面中,我正在扩展网站的主页,就像我看到的其他页面一样。这是主页 home.html (/core/templates/core/home.html):

{% load i18n easy_thumbnails_tags static %}
<!DOCTYPE html>
<html lang="en">
<head>
    {% load staticfiles i18n menu_tags%}
</head>
<main>
    <div class="container">
        {% block content %}

这是我的新页面newpage.html (/newpage/templates/newpage/newpage.html)

{% extends "home.html" %}
{% load easy_thumbnails_tags i18n static core_filters bootstrap4 %}
{% block content %}
    {% load bootstrap4 %}
    <div class="container">

创建新页面后,我通过 Django CMS 栏将其添加到网站主菜单。我将页面模板选择为父(家)使用的模板。我看到这只会在数据库中进行更改。好的,现在我在主页菜单和 Django CMS 模块中有这个页面。

我遇到的问题是我无法从 Django CMS 栏编辑页面结构。当我单击“编辑”按钮时,我看到了结构图标 (www.localhost:8000/newpage/?structure),但该按钮未激活。我希望能够向此页面添加小部件。我该怎么做?如何激活修改结构的可能性?

在这个项目中,我看到一些页面可以修改页面结构,而另一些则没有。也许相关,当我检查具有这种可能性的其他页面的来源时,我看到:

    'request': {
        'language': 'en',
        'model': 'cms.page',
        'page_id': '3',
        'pk': '3',
        'url': '/admin/cms/page/resolve/',
        'toolbar': '/admin/cms/usersettings/cms-toolbar/'
    },

在我的新页面上我看到了:

    'request': {
        'language': 'en',
        'model': '',
        'page_id': '103',
        'pk': '',
        'url': '/admin/cms/page/resolve/',
        'toolbar': '/admin/cms/usersettings/cms-toolbar/'
    },

我使用 Python 3.6.9、Django 1.11.17 和 django-cms 3.5.3。 我知道我可能会丢失一些相关的信息/代码来显示。求问,我来发帖。

【问题讨论】:

    标签: python html django django-templates django-cms


    【解决方案1】:

    您需要加载 CMS 的可编辑部分。这主要是一个占位符,以便您可以通过结构视图添加内容。

    newpage.html 更改为类似;

    {% extends "home.html" %}
    {% load cms_tags easy_thumbnails_tags i18n static core_filters bootstrap4 %}
    
    {% block content %}
        {% load bootstrap4 %}
        <div class="container">
            {% placeholder "content" %}
        </div>
    {% endblock %}
    

    现在您会在结构视图中看到一个名为“内容”的占位符,您可以在其中添加插件。

    【讨论】:

    • 感谢@markwalker_,修复了按钮。不幸的是,结构选项卡完全是灰色的,里面没有元素,也没有像我看到的其他页面那样添加任何插件的选项。你知道我还缺少什么吗?
    • 你的意思是结构按钮被禁用了?如果页面上没有任何占位符,就会发生这种情况。如果结构选项卡打开,它将在页面上显示占位符并带有“+”按钮,然后您可以添加插件。看这里; ibb.co/JsYvc3y
    • 你好@markwalker_。好吧,{% placeholder "content" %} 启用了按钮,但我看不到添加元素的选项。在其他页面中,我有内容块(您有文本)和向其中添加元素的选项。见ibb.co/MfPKrBk。我怎样才能做到这一点?
    • @start.stack1 好的,这并不明显是什么原因造成的。您是否指定了CMS_PLACEHOLDER_CONF 的设置?如果您更改占位符名称,它会显示吗?
    • 我在 CMS_PLACEHOLDER_CONF = {} 有空配置。不,如果我将{% placeholder "content" %} 更改为{% placeholder "contrrenttt" %} 之类的其他名称,那么结构按钮将再次被禁用。
    猜你喜欢
    • 2013-08-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多