如何为djangocms-blog设置自定义模板?

时间:2015-07-27 12:25:07

标签: django django-templates django-cms

我有一个基于djangocms的网站,现在我希望有一个应用程序可以帮助一个小博客部分。

现在,我已成功将djangocms-blog集成到我的网站中,但是当我尝试查看帖子时,模板(由我制作的自定义模板)不会呈现,而帖子(来自博客管理员)只是在页面上抛出。

有人可以帮我解决这个问题吗?您是否想要任何其他信息以帮助我解决这个问题?

我的模板如下所示:

{% extends "base.html" %}
{% load cms_tags %}

{% block title %}{% page_attribute "page_title" %}{% endblock title %}

{% block content %}

    <div class="spacer"></div>
    <div class="page-header page-header-blog-post-1 white">
        <div class="page-header-container container">
            <div class="page-header-content">
                <h1 class="heading">BLOG</h1>
            </div>
        </div>
    </div>


    <div class="blog-container blog-single container">
        <div class="row">
            <div class="col-md-8 blog-content margin-bottom-70 clearfix">
                {% placeholder banner_leaderboard_top %}
            </div>
        </div>
        <div class="row">
            <div class="col-md-8 blog-content margin-bottom-70 clearfix">
                <article id="post-1" class="post-1 post format-standard">
                    <header class="entry-header">
                        <div class="post-thumbnail-area">
                            {% placeholder "post_header_image" or %}
                            <img src="/static/img/onepage-slide9.jpg" alt="image_blog"/>
                            {% endplaceholder %}
                        </div>
                    </header>
                    <div class="entry-content">
                        <div class="entry-title blog-info">
                            <h1 class="heading">{% placeholder "post_header_title" or %}POST_TITLE{% endplaceholder %}</h1>
                        </div>
                        {% placeholder "POST_BODY" or %}POST_BODY{% endplaceholder %}
                    </div>
                    <footer class="entry-footer">
                        <div class="entry-description">
                            <h6 class="post-date-classic">{% placeholder "post_date" or %}POST_DATE{% endplaceholder %}</h6>
                        </div>
                    </footer>
                </article>
                <div class="post-additional">
                    <script type="text/javascript">
                        // Popup window code
                        function newPopup(url) {
                            popupWindow = window.open(
                                    url, 'popUpWindow', 'height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
                        }
                    </script>
                    <ul class="post-share list-inline">
                        <li><a href="JavaScript:newPopup('https://www.facebook.com/sharer/sharer.php?u='+window.location.href)"><i
                                class="icon ion-social-facebook"></i></a></li>
                        <li><a href="JavaScript:newPopup('http://twitter.com/home/?status=Nice blog post - '+window.location.href);"><i
                                class="icon ion-social-twitter"></i></a></li>
                        <li><a href="JavaScript:newPopup('https://plus.google.com/share?url='+window.location.href); "><i
                                class="icon ion-social-googleplus"></i></a></li>
                    </ul>
                    <div class="post-navigation nav-links">
                        <ul class="post-controls list-inline">
                            <li>
                                {% placeholder "prev_post" or %}
                                <a class="post-prev" href="#"><i class="icon ion-ios7-arrow-thin-left"></i></a></li>
                                {% endplaceholder %}
                            <li>
                                {% placeholder "next_post" or %}
                                <a class="post-next" href="#"><i class="icon ion-ios7-arrow-thin-right"></i></a></li>
                                {% endplaceholder %}
                        </ul>
                    </div>
                </div>
                <div class="author-bio">
                    <div class="row">
                        <div class="author-avatar col-xs-4 col-sm-3 col-md-3 visible-desktop">
                            {% placeholder "author_img" or %}
                            <img src="/static/img/image-8.jpg" alt="image_blog"></div>
                            {% endplaceholder %}
                        <div class="author-details white col-md-9">
                            <h3>{% placeholder "author_name" or %}AUTHOR_NAME{% endplaceholder %}</h3>
                            <p>{% placeholder "author_body" or %}AUTHOR_BODY{% endplaceholder %}</p>
                        </div>
                    </div>
                </div>
                {% placeholder banner_leaderboard_bottom %}
            </div>
            <div class="col-md-4">
                <div class="sidebar">

                    <aside id="recent-posts-2" class="widget widget_recent_entries">
                        <div class="widget-title">
                            <h5 class="heading">RECENT POSTS</h5>

                            <div class="fancy-line-small"></div>
                        </div>
                            {% placeholder "post_recent" or %}
                            <ul>
                                <li><a href="#">Recent blog post</a></li>
                            </ul>
                            {% endplaceholder %}
                    </aside>

                {% placeholder banner_square_right %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}

管理djangocms-blog的一些图片:

enter image description here

因此,我希望博客管理员标题应用于我的模板而不是<h1 class="heading">BLOG</h1>,依此类推datecategory等等

1 个答案:

答案 0 :(得分:4)

如果要覆盖已安装的应用使用的模板,则只需模仿模板目录中的相同模板路径。

可以找到CMS博客模板here

因此,要覆盖CMS博客模板,您应该决定需要覆盖哪个模板,在这种情况下,它听起来像post_detail.html,因为您关注帖子的显示方式。

所以在你的项目中你需要创造类似的东西; myproj/templates/djangocms_blog/post_detail.html

然后系统将从site-packages文件夹加载那个而不是post_detail.html