[Django]-What is the difference render() and redirect() in Django?

12👍

Both are totally different where the redirect gives the HttpResponseRedirect for
the argument you have passed.

example

return redirect('https://example.com/')  

takes you to the https://example.com/ page

 return render(request,'/result.html',{'foo':'bar'})

renders the context dictionary in to the template ‘result.html’ and returns an HttpResponse object with that rendered text

result.html

{foo}

where foo will replaced by bar

For more details look in to this django docs

10👍

The render function Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.

You request a page and the render function returns it.

The redirect function sends another request to the given url.

Leave a comment