from blog.models import BlogEntry, BlogSection
from django.http import Http404, HttpResponse
+from django.shortcuts import render
from django.template import RequestContext, loader
from django.core.paginator import Paginator
from django.conf import settings
try:
paginated_entries = paginator.page(page)
pages = paginator.page_range
- t = loader.get_template("blog/blog_index.html")
- c = RequestContext(request,
- {
+ c = {
"entries": paginated_entries.object_list,
"title": settings.BLOG_TITLE,
"page": page,
"has_prev": paginated_entries.has_previous(),
"next": page + 1,
"prev": page - 1
- })
- return HttpResponse(t.render(c))
+ }
+ return render(request, 'blog/blog_index.html', c)
except:
raise Http404
else:
try:
blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug)
template_name = "blog/single_entry_%s.html" %(blog_entry.format,)
- t = loader.get_template(template_name)
- c = RequestContext(request,
- {
+ c = {
"entry": blog_entry,
"publish_date": blog_entry.publish_date
}
- )
- return HttpResponse(t.render(c))
+ return render(request, template_name, c)
except:
raise Http404
else:
try:
paginated_entries = paginator.page(page)
pages = paginator.page_range
- t = loader.get_template("blog/blog_index.html")
- c = RequestContext(request,
- {
+ c = {
"entries": paginated_entries.object_list,
"title": settings.BLOG_TITLE,
"page": page,
"has_prev": paginated_entries.has_previous(),
"next": page + 1,
"prev": page - 1
- })
- return HttpResponse(t.render(c))
+ }
+ return render(request, "blog/blog_index.html", c)
except:
raise Http404
else: