I’m confused about the code example at the end of the resolve documentation (“test whether a view would raise a Http404 error before redirecting to it”). Could someone provide explanation about this code -what it’s doing and how it works? I haven’t a clue what’s going on.
For example, why would you need to call a view to test if it throws a 404, when resolve itself can throw Resolver404? When the code calls the view function, it gives it the request via a keyword argument but with other arguments before that. But shouldn’t a view get request as its first argument? Why is the referer header being used?
Thanks
Resolver404is only thrown if the path doesn’t resolve to a URL/View function.The view function itself can still raise a 404 depending on input parameters, like a bad ID.
Theres 2 issues:
'^/(?P<foo>\d+)\d/$'foodoesn’t raise a 404.You’re right that with the example,
requestshould be the first argument. If there are any url*args(unnamed regexp matches), request would be added twice since it’s typically the first argument. Perhaps a bug in the example?