def post_detail(request, slug):
    post = get_object_or_404(Post, slug=slug)
    if (request.method == 'POST'):
        if request.user:
            form = CommentForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.post = post
                instance.save()
                messages.add_message(request, messages.SUCCESS, 'Comment Added')
    form = CommentForm()
    return render(request, 'blog/post_detail.html', {'post': post, 'form': form})
def post_detail(request, slug):
    post = get_object_or_404(Post, slug=slug)
    if (request.method == 'POST'):
        if request.user:
            form = CommentForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.post = post
                instance.save()
                messages.add_message(request, messages.SUCCESS, 'Comment Added')
    form = CommentForm()
    return render(request, 'blog/post_detail.html', {'post': post, 'form': form})