【问题标题】:How mezzanine templating works?夹层模板如何工作?
【发布时间】:2018-10-07 05:35:42
【问题描述】:

我有一个夹层网站,我试图在该网站中显示博客中的热门故事块。我可以显示最近的帖子,但是当我尝试为热门故事添加内容时,它无法正常工作。我不知道如何添加这个模块。有任何想法吗? 我附上最近帖子的代码

<div class="section_content">
<div class="grid clearfix">
    <div>
        {% load blog_tags keyword_tags mezzanine_tags i18n %}
        {% blog_recent_posts 1 as recent_posts %}
        {% if recent_posts %}
        {% for recent_post in recent_posts %}

        <div class="card card_largest_with_image grid-item">
            {% spaceless %}
            <a class="text-capitalize" href="{{ recent_post.get_absolute_url }}">
                {% if settings.BLOG_USE_FEATURED_IMAGE and recent_post.featured_image %}
                <img class="card-img-top" src="{{ MEDIA_URL }}{% thumbnail recent_post.featured_image 610 193 %}">
                {% endif %}
            </a>
            {% endspaceless %}

            <div class="card-body">
                <div class="card-title"><a href="{{ recent_post.get_absolute_url }}">{{ recent_post.title }}</a></div>
                <p class="card-text">{{ recent_post.description|safe }}</p>
                <small class="post_meta"><span>{{ recent_post.publish_date|timesince }} {% trans "ago" %}</span></small>
            </div>
        </div>
        {% endfor %}
        {% endif %}
    </div>
    {% blog_recent_posts 5 as recent_posts %}
    {% if recent_posts %}
    {% for recent_post in recent_posts %}
    <div class="card card_default card_small_with_background grid-item">
        {% spaceless %}
        <a class="text-capitalize" href="{{ recent_post.get_absolute_url }}">
            {% if settings.BLOG_USE_FEATURED_IMAGE and recent_post.featured_image %}
            <div class="card_background" style="background-image:url({{ MEDIA_URL }}{% thumbnail recent_post.featured_image 263 165 %}); height: 163px; width:265px;"></div>
            {% endif %}
            {% endspaceless %}
            <div class="card-body">
                <div class="card-title card-title-small"><a href="{{ recent_post.get_absolute_url }}">{{
                        recent_post.title }}</a></div>
                <small class="post_meta"><span>{{ recent_post.publish_date|timesince }} {% trans "ago" %}</span></small>
            </div>
    </div>
    {% endfor %}
    {% endif %}
</div>

提前致谢

【问题讨论】:

    标签: django mezzanine


    【解决方案1】:

    我研究了一整天,发现有类似模板标签的东西,您只需将模板标签添加到您的应用程序中,您就可以创建新标签并覆盖旧标签。更多信息可以参考:https://docs.djangoproject.com/en/2.1/howto/custom-template-tags/

    【讨论】:

      猜你喜欢
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 2013-05-26
      • 2021-03-22
      • 2017-11-27
      • 2013-09-17
      相关资源
      最近更新 更多