Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.0 kB
0
Indexable
Never
def profile(request, username):
    user = get_object_or_404(User, username=username)
    full_name = user.get_full_name()
    posts = Post.objects.filter(author=user).all()
    number_of_posts = posts.count()

    paginator = Paginator(posts, 10)
    page_number = request.GET.get('page')
    page = paginator.get_page(page_number)

    context = {
        'username': username,
        'user_full_name': full_name,
        'number_of_posts': number_of_posts,
        'page': page
    }

    return render(request, 'profile.html', context)


def post_view(request, username, post_id):
    user = get_object_or_404(User, username=username)
    full_name = user.get_full_name()
    posts = Post.objects.filter(author=user).all()
    number_of_posts = posts.count()
    post = get_object_or_404(Post, pk=post_id)

    context = {
        'username': username,
        'user_full_name': full_name,
        'number_of_posts': number_of_posts,
        'post': post
    }

    return render(request, 'post.html', context)