Can someone please explain what is going on here with the Django Tutorial Part 4
Specifically, how the map function is working?
I understand that URLs shouldn't be hardcoded in the view functions.
return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,)))
The reverse
function has access to the URL map that Django uses to find a view function for incoming URLs. In this case, you pass in a view function, and the arguments it will get, and it finds the URL that would map to it. Then the HttpResponseRedirect function creates a response that directs the browser to visit that URL.
This is a way of saying, "Now call the mysite.polls.views.results view."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With