how to start integrating django-cms into existing project

回眸只為那壹抹淺笑 提交于 2019-12-25 02:58:46

问题


My purpose is to convert static pages (about us, contact us etc) in my existing project to admin editable pages. I have followed the instructions at the tutorial to get things started but don't seem to get any results. So far performing python manage.py cms check seems to indicate I got everything set up. But I don't seem to get the urls right. It says here

You need to include the 'cms.urls' urlpatterns at the end of your urlpatterns.

My urls are as follows:

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

When I type http://localhost:8000?edit, the cms toolbar/menus didn't show up. Neither do the page that inherited the template I created below shows any placeholder for editing when I suffixed the url with ?edit.

Any idea where did I go wrong?

{% 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> 

回答1:


Two things, remove, what I assume to be, your project URLs as that might cause you some issues. But if you need it, don't just match the base pattern as I consider that bad practise until you do a lot of specific pattern matches in that file which aren't likely to break the CMS URLs.

Then add the {% cms_toolbar %} tag to your base template in order to ensure the toolbar displays & you can interact with the 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> 


来源:https://stackoverflow.com/questions/31167313/how-to-start-integrating-django-cms-into-existing-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!