i am trying to create a function to save favourite post to users profile, this is working fine in the database it adds and removes the favourite post but when the view is called it shows this error The view books.views.save didn’t return an HttpResponse object. It returned None instead.
def save(request, book_slug):
user = request.user
book = Book.objects.get(slug=book_slug)
post = get_object_or_404(Book, slug=request.POST.get('post_slug'))
profile = Profile.objects.get(user=user)
is_saved = False
if profile.favourite_book.filter(slug=book_slug).exists():
profile.favourite_book.remove(post)
is_saved = False
else:
profile.favourite_book.add(post)
is_saved = True
context = {
'book':book,
'post':post,
'is_saved':is_saved,
}
if request.is_ajax():
html = render_to_string('books/save_section.html', context, request=request)
return JsonResponse({'form': html})