From 516051bfd2b537f441c46359cce7eacbf15fc4b8 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 31 Mar 2009 23:34:03 +0000 Subject: A whole lotta documentation fixes: Fixes #8704, #8826, #8980, #9243, #9343, #9529, git-svn-id: http://code.djangoproject.com/svn/django/trunk@10303 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/topics/http/shortcuts.txt | 2 +- docs/topics/http/urls.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'docs/topics/http') diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index 64633aae12..2bc35a3b9f 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -26,7 +26,7 @@ Required arguments ------------------ ``template`` - The full name of a template to use. + The full name of a template to use or sequence of template names. Optional arguments ------------------ diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index 0d0f9ac889..4248d4f02e 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -633,6 +633,40 @@ reverse such patterns. be imported correctly. Do not include lines that reference views you haven't written yet, because those views will not be importable. +resolve() +--------- + +The :func:`django.core.urlresolvers.resolve` function can be used for resolving +URL paths to the corresponding view functions. It has the following signature: + +.. currentmodule:: django.core.urlresolvers +.. function:: resolve(path, urlconf=None) + +``path`` is the URL path you want to resolve. As with ``reverse()`` above, you +don't need to worry about the ``urlconf`` parameter. The function returns the +triple (view function, arguments, keyword arguments). + +For example, it can be used for testing if a view would raise a ``Http404`` +error before redirecting to it:: + + from urlparse import urlparse + from django.core.urlresolvers import resolve + from django.http import HttpResponseRedirect, Http404 + + def myview(request): + next = request.META.get('HTTP_REFERER', None) or '/' + response = HttpResponseRedirect(next) + + # modify the request and response as required, e.g. change locale + # and set corresponding locale cookie + + view, args, kwargs = resolve(urlparse(next)[2]) + kwargs['request'] = request + try: + view(*args, **kwargs) + except Http404: + return HttpResponseRedirect('/') + return response permalink() ----------- -- cgit v1.3