diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-09-11 22:36:16 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-09-11 22:36:16 +0000 |
| commit | 26b812208751edf87b4df0aee00996c5c7bcd4c9 (patch) | |
| tree | 0857822a7dbd27f459b9dfe2075bf194a3e16ce8 /docs/topics | |
| parent | fd9045346286208c0dbd0afc1f820e868910dac8 (diff) | |
Fixed #14675 -- Completed removal of `from django.conf.urls.default import *` usage.
This applies to both our own [test] code and documentation examples. Also:
* Moved the functions and handlers from `django.conf.urls.defaults` up to
`django.conf.urls` deprecating the former module.
* Added documentation for `handler403`.
* Tweaked the URLs topic document a bit.
Thanks to pupeno and cdestigter for their great work contributing patches.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/class-based-views.txt | 6 | ||||
| -rw-r--r-- | docs/topics/generic-views.txt | 6 | ||||
| -rw-r--r-- | docs/topics/http/urls.txt | 61 | ||||
| -rw-r--r-- | docs/topics/i18n/internationalization.txt | 6 |
4 files changed, 51 insertions, 28 deletions
diff --git a/docs/topics/class-based-views.txt b/docs/topics/class-based-views.txt index 8092cb29af..62368faee1 100644 --- a/docs/topics/class-based-views.txt +++ b/docs/topics/class-based-views.txt @@ -75,7 +75,7 @@ views themselves are classes, we point the URL to the ``as_view`` class method instead, which is the entry point for class-based views:: # urls.py - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from some_app.views import AboutView urlpatterns = patterns('', @@ -86,7 +86,7 @@ Alternatively, if you're only changing a few simple attributes on a class-based view, you can simply pass the new attributes into the ``as_view`` method call itself:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from django.views.generic import TemplateView urlpatterns = patterns('', @@ -135,7 +135,7 @@ be using these models:: To build a list page of all publishers, we'd use a URLconf along these lines:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from django.views.generic import ListView from books.models import Publisher diff --git a/docs/topics/generic-views.txt b/docs/topics/generic-views.txt index 9251b3ad44..78c3c0199f 100644 --- a/docs/topics/generic-views.txt +++ b/docs/topics/generic-views.txt @@ -58,7 +58,7 @@ URLconf tuple for a given pattern. For example, here's a simple URLconf you could use to present a static "about" page:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from django.views.generic.simple import direct_to_template urlpatterns = patterns('', @@ -80,7 +80,7 @@ the URLconf to point to a view function: .. parsed-literal:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from django.views.generic.simple import direct_to_template **from books.views import about_pages** @@ -160,7 +160,7 @@ be using these models:: To build a list page of all publishers, we'd use a URLconf along these lines:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include from django.views.generic import list_detail from books.models import Publisher diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index c1a15ab229..18789b3f25 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -50,7 +50,7 @@ algorithm the system follows to determine which Python code to execute: 2. Django loads that Python module and looks for the variable ``urlpatterns``. This should be a Python list, in the format returned by - the function :func:`django.conf.urls.defaults.patterns`. + the function :func:`django.conf.urls.patterns`. 3. Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL. @@ -69,7 +69,7 @@ Example Here's a sample URLconf:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('', (r'^articles/2003/$', 'news.views.special_case_2003'), @@ -80,9 +80,6 @@ Here's a sample URLconf:: Notes: - * ``from django.conf.urls.defaults import *`` makes the ``patterns()`` - function available. - * To capture a value from the URL, just put parenthesis around it. * There's no need to add a leading slash, because every URL has that. For @@ -184,13 +181,21 @@ Syntax of the urlpatterns variable ================================== ``urlpatterns`` should be a Python list, in the format returned by the function -:func:`django.conf.urls.defaults.patterns`. Always use ``patterns()`` to create +:func:`django.conf.urls.patterns`. Always use ``patterns()`` to create the ``urlpatterns`` variable. -Convention is to use ``from django.conf.urls.defaults import *`` at the top of -your URLconf. This gives your module access to these objects: +``django.conf.urls`` utility functions +====================================== + +.. module:: django.conf.urls -.. module:: django.conf.urls.defaults +.. deprecated:: 1.4 + Starting with Django 1.4 functions ``patterns``, ``url``, ``include`` plus + the ``handler*`` symbols described below live in the ``django.conf.urls`` + module. + + Until Django 1.3 they were located in ``django.conf.urls.defaults``. You + still can import them from there but it will be removed in Django 1.6. patterns -------- @@ -281,6 +286,24 @@ URLconf will have no effect. See the documentation on :ref:`customizing error views <customizing-error-views>` for more details. +handler403 +---------- + +.. data:: handler403 + +A callable, or a string representing the full Python import path to the view +that should be called if the user has no the permissions required to access +a resource. + +By default, this is ``'django.views.defaults.permission_denied'``. That default +value should suffice. + +See the documentation about :ref:`the 403 (HTTP Forbidden) view +<http_forbidden_view>` for more information. + +.. versionadded:: 1.4 + ``handler403`` is new in Django 1.4. + handler404 ---------- @@ -355,7 +378,7 @@ code duplication. Here's the example URLconf from the :doc:`Django overview </intro/overview>`:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('', (r'^articles/(\d{4})/$', 'news.views.year_archive'), @@ -370,7 +393,7 @@ each view function. With this in mind, the above example can be written more concisely as:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('news.views', (r'^articles/(\d{4})/$', 'year_archive'), @@ -391,7 +414,7 @@ Just add multiple ``patterns()`` objects together, like this: Old:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('', (r'^$', 'django.views.generic.date_based.archive_index'), @@ -401,7 +424,7 @@ Old:: New:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('django.views.generic.date_based', (r'^$', 'archive_index'), @@ -421,7 +444,7 @@ essentially "roots" a set of URLs below other ones. For example, here's the URLconf for the `Django Web site`_ itself. It includes a number of other URLconfs:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include urlpatterns = patterns('', (r'^weblog/', include('django_website.apps.blog.urls.blog')), @@ -439,7 +462,7 @@ Another possibility is to include additional URL patterns not by specifying the URLconf Python module defining them as the `include`_ argument but by using directly the pattern list as returned by `patterns`_ instead. For example:: - from django.conf.urls.defaults import * + from django.conf.urls import patterns, url, include extra_patterns = patterns('', url(r'reports/(?P<id>\d+)/$', 'credit.views.report', name='credit-reports'), @@ -784,8 +807,8 @@ following would happen: * ``foo:index`` will again resolve to the index page of the instance ``foo``. -Utility methods -=============== +``django.core.urlresolvers`` utility functions +============================================== .. currentmodule:: django.core.urlresolvers @@ -793,7 +816,7 @@ reverse() --------- If you need to use something similar to the :ttag:`url` template tag in -your code, Django provides the following method (in the +your code, Django provides the following function (in the :mod:`django.core.urlresolvers` module): .. function:: reverse(viewname, [urlconf=None, args=None, kwargs=None, current_app=None]) @@ -859,7 +882,7 @@ reverse_lazy() A lazily evaluated version of `reverse()`_. It is useful for when you need to use a URL reversal before your project's -URLConf is loaded. Some common cases where this method is necessary are: +URLConf is loaded. Some common cases where this function is necessary are: * providing a reversed URL as the ``url`` attribute of a generic class-based view. diff --git a/docs/topics/i18n/internationalization.txt b/docs/topics/i18n/internationalization.txt index dbeb77c879..744509638d 100644 --- a/docs/topics/i18n/internationalization.txt +++ b/docs/topics/i18n/internationalization.txt @@ -819,11 +819,11 @@ Language prefix in URL patterns .. function:: i18n_patterns(prefix, pattern_description, ...) This function can be used in your root URLconf as a replacement for the normal -:func:`django.conf.urls.defaults.patterns` function. Django will automatically +:func:`django.conf.urls.patterns` function. Django will automatically prepend the current active language code to all url patterns defined within :func:`~django.conf.urls.i18n.i18n_patterns`. Example URL patterns:: - from django.conf.urls.defaults import patterns, include, url + from django.conf.urls import patterns, include, url from django.conf.urls.i18n import i18n_patterns urlpatterns = patterns('' @@ -877,7 +877,7 @@ Translating URL patterns URL patterns can also be marked translatable using the :func:`~django.utils.translation.ugettext_lazy` function. Example:: - from django.conf.urls.defaults import patterns, include, url + from django.conf.urls import patterns, include, url from django.conf.urls.i18n import i18n_patterns from django.utils.translation import ugettext_lazy as _ |
