| | 639 | The :func:`django.core.urlresolvers.resolve` function can be used for resolving |
| | 640 | URL paths to the corresponding view functions. It has the following signature: |
| | 641 | |
| | 642 | .. currentmodule:: django.core.urlresolvers |
| | 643 | .. function:: resolve(path, urlconf=None) |
| | 644 | |
| | 645 | ``path`` is the URL path you want to resolve. As with ``reverse()`` above, you |
| | 646 | don't need to worry about the ``urlconf`` parameter. The function returns the |
| | 647 | triple (view function, arguments, keyword arguments). |
| | 648 | |
| | 649 | For example, it can be used for testing if a view would raise a ``Http404`` |
| | 650 | error before redirecting to it:: |
| | 651 | |
| | 652 | from urlparse import urlparse |
| | 653 | from django.core.urlresolvers import resolve |
| | 654 | from django.http import HttpResponseRedirect, Http404 |
| | 655 | |
| | 656 | def myview(request): |
| | 657 | next = request.META.get('HTTP_REFERER', None) or '/' |
| | 658 | response = HttpResponseRedirect(next) |
| | 659 | |
| | 660 | # modify the request and response as required, e.g. change locale |
| | 661 | # and set corresponding locale cookie |
| | 662 | |
| | 663 | view, args, kwargs = resolve(urlparse(next)[2]) |
| | 664 | try: |
| | 665 | view(*args, **kwargs) |
| | 666 | except Http404: |
| | 667 | return HttpResponseRedirect('/') |
| | 668 | return response |
| | 669 | |