【问题标题】:how to start integrating django-cms into existing project如何开始将 django-cms 集成到现有项目中
【发布时间】:2015-09-18 23:08:24
【问题描述】:

我的目的是将现有项目中的静态页面(关于我们、联系我们等)转换为管理员可编辑页面。我已按照tutorial 的说明开始工作,但似乎没有得到任何结果。到目前为止,执行python manage.py cms check 似乎表明我已经完成了所有设置。但我似乎没有得到正确的网址。这里说

您需要在末尾包含“cms.urls”urlpatterns url 模式。

我的网址如下:

urlpatterns = patterns('',
                       url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
                       # Uncomment the next line to enable the admin:
                       url(r'^admin/', include(admin.site.urls)),
                       # Main site
                       url(r'^', include('website.urls')),
                       url(r'^', include('cms.urls')),
)

if settings.DEBUG:
    import debug_toolbar

    urlpatterns = patterns('',
                           url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
                               {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
                           url(r'', include('django.contrib.staticfiles.urls')),
                           url(r'^__debug__/', include(debug_toolbar.urls)),
    ) + urlpatterns

当我输入http://localhost:8000?edit 时,cms 工具栏/菜单没有出现。当我使用 ?edit 为 url 添加后缀时,继承了我在下面创建的模板的页面也没有显示任何用于编辑的占位符。

知道我哪里做错了吗?

{% load cms_tags sekizai_tags %}

<!doctype html>
<html>
<head>
    {% include "head.html" %}
    {% block page_specific %}
    {% endblock %}
    {% render_block "css" %}
    {% render_block "js" %}
</head>

<body>

<!--{% include "floating_login.html" %}-->

<section id="subpage_wrapper">
    {% with include_ribbon=1 %}
        {% include "nav_base.html" %}
    {% endwith %}

    <div id="sub_wrapper_white">
        {% placeholder "feature" %}
        {% block static_content %}

        {% endblock static_content %}
    </div>


    <div id="sub_wrapper_red"></div>
    <div id="sub_wrapper_yellow"></div>

</section>


</body>
</html> 

【问题讨论】:

  • 顺便说一句,http://localhost:8000?edit 无论如何都不会工作。它必须是http://localhost:8000/?edit
  • 谢谢,也试过了,但是主页还是没有以前的样子。
  • @goh 你确定你的尝试最终不会被路由到website.urls吗?如果其中的任何内容与您尝试访问的 URL 匹配,则 Django CMS 将看不到该请求。
  • 你错过了{% cms_toolbar %}(最好是在&lt;body&gt;之后)让?edit工作

标签: django django-cms


【解决方案1】:

删除我认为的两件事,您的项目 URL,因为这可能会给您带来一些问题。但是,如果您需要它,请不要只匹配基本模式,因为我认为这是不好的做法,直到您在该文件中执行许多特定模式匹配,这些匹配不太可能破坏 CMS URL。

然后将{% cms_toolbar %} 标签添加到您的基本模板中,以确保工具栏显示出来并且您可以与 CMS 进行交互。

urls.py

urlpatterns = patterns('',
                       url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
                       # Uncomment the next line to enable the admin:
                       url(r'^admin/', include(admin.site.urls)),
                       # Main site
                       url(r'^project/', include('website.urls')),
                       url(r'^', include('cms.urls')),
)

base.html

{% load cms_tags sekizai_tags %}

<!doctype html>
<html>
<head>
    {% include "head.html" %}
    {% block page_specific %}
    {% endblock %}
    {% render_block "css" %}
    {% render_block "js" %}
</head>

<body>
{% cms_toolbar %}
<!--{% include "floating_login.html" %}-->

<section id="subpage_wrapper">
    {% with include_ribbon=1 %}
        {% include "nav_base.html" %}
    {% endwith %}

    <div id="sub_wrapper_white">
        {% placeholder "feature" %}
        {% block static_content %}

        {% endblock static_content %}
    </div>
    <div id="sub_wrapper_red"></div>
    <div id="sub_wrapper_yellow"></div>

</section>


</body>
</html> 

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 2021-07-30
    • 1970-01-01
    • 2012-03-28
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    相关资源
    最近更新 更多