Fetch blog entries with bootstrap custom theme and

2019-07-24 17:40发布

I'm new to mezzanine, I managed to install my custom bootstrap theme just copying templates and static files in the relatives folders in my django app.

Assume in my index.html I have some blog entries like these

<h2>Other Entries</h2>
<article>
<h3>Blog Post 1</h3>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text.... <a href="#">Read more</a></p>
</article>
<article>
<h3>Blog Post 2</h3>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text.... <a href="#">Read more</a></p>
</article>
<article>
<h3>Blog Post 3</h3>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text.... <a href="#">Read more</a></p>
</article>

How can I fetch my blog entries I've previously inserted in the admin page?

Thanks

1条回答
一夜七次
2楼-- · 2019-07-24 17:50

At the top of your template put:

{% load blog_tags %}

Then wherever you want the blog posts to show up put something like the following

{% blog_recent_posts as recent_posts %}
{% for blog_post in recent_posts %}
<h3>{{ blog_post.title }}</h3>
{{ blog_post.description_from_content|truncatewords_html:10|safe }}
<a href="{{ blog_post.get_absolute_url }}">Read more</a>
</article>
{% endfor %}

Shameless plug: I'm in the middle of writing a series of blog posts that describes the process of how I create themes for Mezzanine. Check it out, http://bitofpixels.com/blog/mezzatheming-creating-mezzanine-themes-part-1-basehtml/

查看更多
登录 后发表回答