According to the docs, redirect
takes either of the following three:
- A model: the model’s
get_absolute_url()
function will be called. - A view name, possibly with arguments:
urlresolvers.reverse
will be used to reverse-resolve the name. - An absolute or relative URL, which will be used as-is for the redirect location.
By passing a string not started with a protocol and doesn't contain slashes, the argument is recognised as a name, and is passed into reverse
.
The wording is maybe a bit misleading here. reverse
looks up a view by its URL pattern name, so when the document says that it takes a view name it actually means the name of a URL pattern that points to a view, not the name of the view itself. Since reverse
looks in your urlpatterns
(in urls.py
) for URL patterns, you need to add testpage
into it so that it can be found by reverse
:
url(r'^whatever/$', testpage, name='testpage')
Obviously you can put any pattern you wish in the first argument, and need to import the view function for the second argument. The name
part is what reverse
uses to look up the URL.