Home > database >  What is the difference between "return HttpResponseRedirect(reverse("index"))" a
What is the difference between "return HttpResponseRedirect(reverse("index"))" a

Time:08-16

The instructor prefers the redirect function on that line instead of return render but hasn't clarified why and the differences between the two.

CodePudding user response:

the render function is just to render the template and fill it with context data from the view and return a response with Html after the rendering has been done refer for documentation to read more https://docs.djangoproject.com/en/4.1/topics/http/shortcuts/#render so it returns status code like 20x success

but in the case of HTTP response redirect it returns code of 301 or 302 to tell the browser to redirect to new given URL in your case it will be reverse("index") so every on of each has different use

  • Related