Reputation: 120
I have followed a tutorial for making a blog engine and successfully integrated it. It is just this template that is not working, I have no idea why. What can be the problem?
Here is the template:
{% extends "base.html" %}
{% block title %}{% post.title %}{% endblock %}
{% block content %}
<h3>{{ post.title }}</h3>
<p>Posted on {{ post.published|date:"F j, Y" }}<p>
{{ post.description|safe }}
<br>
{{ post.body|safe }}
<br>
{% if previous_post %}
<a href="{{ previous_post.get_absolute_url }}" title="{{ previous_post.title }}">
« Previous Post: {{ previous_post.title }}
</a>{% endif %}
{% if previous_post and next_post %} | {% endif %}
{% if next_post %}
<a href="{{ next_post.get_absolute_url }}" title="{{ next_post.get_absolute_url }}">
Next Post: {{ next_post.title }} »
</a>
{% endif %}
{% endblock content %}
And here is views.py:
def detail(request, sl):
try:
post = Post.objects.filter(slug=sl)[0]
try:
previous_post = post.get_previous_by_published()
except:
previous_post = ""
try:
next_post = post.get_next_by_published()
except:
next_post = ""
except:
next_post = ""
previous_post = ""
post = ""
return render_to_response('blog/detail.html', {'post':post,
'next_post':next_post,
'previous_post':previous_post,
},)
Upvotes: 0
Views: 2864
Reputation: 120
Ok so I found out and solved my problem. Just wanted to post it here so someone can use it. It was actually a n00b mistake.
So the {{}} weren't rendering because of the fact that there was nothing in "sl" which I calling upon as argument in the function. It was empty because I was following a tutorial and the tutorial didn't explain a very important thing about Django, and that is that the named groups can be added as arguments in functions, and I had no named group called "sl" in my urlconf in the appropriate place. So by adding this:
(r'^([0-9]{4}/\d{1,2})/(?P<sl>.*)/$', detail),
in the urlconf the problem was solved.
Thanks for all the guidance.
Upvotes: 1