from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from .models import *
def posts_wall(request):
object_list = Post.objects.all()
paginator = Paginator(object_list, 5)
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
posts = paginator.page(1)
except EmptyPage:
posts = paginator.page(paginator.num_pages)
return render(request, 'blog/post/paginators.html', {'page' : page, 'posts' : posts})
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug = post, status = 'published', published_year = year,
published_month = month, published_day = day)
return render(request, 'blog/post/detail.html', {'post' : post})
{% extends "blog/base.html" %}
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
<a href="?page={{page.previous_page_number}}">Previous</a>
{% endif %}
<span class="current">
Page {{ page.number }} of {{ page.paginator.num_pages }}.
{% if page.has_next %}
<a href="?page={{ page.next_page_number }}">Next</a>
{% endif %}
</span>
</div>
{% extends "blog/base.html" %}
{% block title %}My Blog{% endblock %}
{% block content %}
<h1 align = 'center'>My Blog</h1>
{% for post in posts %}
<h2>
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
</h2>
<p class="date">Published {{ post.publish }} by {{ post.author }}</p>
{{ post.body|truncatewords:30|linebreaks }}
{% endfor %}
{% include "pagination.html" with page=posts %}
{% endblock %}