1👍
When using the render
function in django, the second argument is the template name.
The string you specify there is used relative to the TEMPLATES
settings you’ve defined in your settings.py. It tells django where the template file is located. This is why you don’t start the template name with ‘/’ in render()
Whereas, HttpResponseRedirect
directly asks for the URL to redirect. It is upto you whether you should add ‘/’ to it before the string.
When the supplied URL starts with ‘/’, no matter where you redirect from, the user is taken to the exact path relative the the website root.
For example, if the user is at http://127.0.0.1:8000/some/other/page/ and you use the following to redirect user:
return HttpResponseRedirect(‘/dashboard/’)
The user will be redirected to http://127.0.0.1:8000/dashboard/
If the URL does not start with ‘/’, the url is just appended to the url from which user is visiting.
In this case:
return HttpResponseRedirect(‘dashboard/’)
User will be taken to http://127.0.0.1:8000/some/other/page/dashboard/