Thursday, March 09, 2006

Building a blog...part 4

Since now we have "post_archive.html". next steps will be to create template so your posts can be categorized by year, month and day.

for post_archive_year.html:


{% extends "base" %}
{% block content %}
<h2>Blog: {{ year }} Archive</h2>
<ul>
{% for date in date_list %}
<li><a href="{{ date|date:"M"|lower }}/">{{ date|date:"F" }}</a></li>
{% endfor %}
</ul>
{% endblock %}


post _archive_month.html:


{% extends "base" %}
{% block content %}
<h2>Blog: {{ month|date:"F" }} {{ year }} Archive</h2>
{% for object in object_list %}
<h2><a id="{{ object.slug }}" href="{{ object.get_absolute_url }}">{{ object.title }}</a></h2>
{% if object.image %}<img align="right" src="{{ object.get_image_url }}" /> {% endif %}
<p>{{ object.body|truncatewords:80 }}</p>

<div class="article_menu"><b>Posted on {{ object.date|date:"F j, Y" }}</b></div>
{% endfor %}
{% endblock %}


post_archive_day.html:


{% extends "base" %}
{% block content %}
<h2>Blog: {{ day|date:"F j, Y" }} Archive</h2>
{% for object in object_list %}
<h2><a id="{{ object.slug }}" href="{{ object.get_absolute_url }}">{{ object.title }}</a></h2>
{% if object.image %}<img align="right" src="{{ object.get_image_url }}" /> {% endif %}
<p>{{ object.body|truncatewords:80 }}</p>

<div class="article_menu"><b>Posted on {{ object.date|date:"F j, Y" }}</b></div>
{% endfor %}
{% endblock %}


and post_detail.html to display single post:


{% extends "base" %}
{% block content %}
<h2>Blog Entry</h2>
{% load comments %}
{% get_free_comment_count for blog.posts object.slug as comment_count %}
<h3><a id="{{ object.slug }}" href="{{ object.get_absolute_url }}">{{ object.title }}</a></h3>

{% if object.image %}<img align="right" src="{{ object.get_image_url }}" />{% endif %}

<p>{{ object.body }}</p>

<div class="article_menu"><b>Posted on {{ object.date|date:"F j, Y" }}</b> Tags: {% for tag in object.get_tag_list %}{% if not forloop.first %}, {% endif %}{{ tag.title }}{% endfor %}
</div>

So now we can access to the blog via
http://127.0.0.1:8000/blog/ for the normal view
http://127.0.0.1:8000/blog/2006/ to view those posted on 2006
http://127.0.0.1:8000/blog/2006/jan/ to view those posted on 2006 January
http://127.0.0.1:8000/blog/2006/jan/05/ to view those posted on 2006, January 05.

All this link work perfectly, except that clicking on the post title, it return a long TemplateSyntaxError,
stating that "'comments' is not a valid tag library: Could not load template library from django.templatetags.comments, No module named comments"
and "In template C:/Python24/Django-0.91/mytemplates/blog/posts_detail.html, error at line 4, 'comments' is not a valid tag library: Could not load template library from django.templatetags.comments, No module named comments"


Still have no time to really look into it, will have to check through all the comments in Rossp, see if other facing the same problem.

1 comment:

Anonymous said...

In settings.py under installed apps you need to add:

'django.contrib.comments',