1👍
✅
You should use a leading slash in the HTTP redirect response:
class AddFavoriteView(View):
def post(self, request):
print(request)
review_id = request.session['favorite_review'] = request.POST['review_id']
return HttpResponseRedirect(f'/reviews/{review_id}')
If you give the path a name, like:
path('reviews/<int:pk>', views.SingleReviewView.as_view(), name='review-details'),
then you can use redirect(…)
[Django-doc] to determine the URL and return the proper HTTP redirect response:
from django.shortcuts import redirect
class AddFavoriteView(View):
def post(self, request):
print(request)
review_id = request.session['favorite_review'] = request.POST['review_id']
return redirect('review-details', pk=review_id)
Source:stackexchange.com