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
This commit is contained in:
Ramiro Morales 2011-09-11 22:36:16 +00:00
parent fd90453462
commit 26b8122087
88 changed files with 243 additions and 198 deletions

View file

@ -78,7 +78,7 @@ point at that file::
Time for an example. Edit ``mysite/urls.py`` so it looks like this::
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
@ -367,7 +367,7 @@ special: It's just a normal view.
You normally won't have to bother with writing 404 views. By default, URLconfs
have the following line up top::
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
That takes care of setting ``handler404`` in the current module. As you can see
in ``django/conf/urls/defaults.py``, ``handler404`` is set to
@ -443,7 +443,7 @@ Namely, ``polls.views`` is in every callback.
Because this is a common case, the URLconf framework provides a shortcut for
common prefixes. You can factor out the common prefixes and add them as the
first argument to :func:`~django.conf.urls.defaults.patterns`, like so::
first argument to :func:`~django.conf.urls.patterns`, like so::
urlpatterns = patterns('polls.views',
(r'^polls/$', 'index'),
@ -457,21 +457,21 @@ tidier.
Since you generally don't want the prefix for one app to be applied to every
callback in your URLconf, you can concatenate multiple
:func:`~django.conf.urls.defaults.patterns`. Your full ``mysite/urls.py`` might
:func:`~django.conf.urls.patterns`. Your full ``mysite/urls.py`` might
now look like this::
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('polls.views',
(r'^polls/$', 'index'),
(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
)
urlpatterns += patterns('',
url(r'^admin/', include(admin.site.urls)),
)
@ -494,23 +494,23 @@ URLs within the app directory.
Copy the file ``mysite/urls.py`` to ``polls/urls.py``. Then, change
``mysite/urls.py`` to remove the poll-specific URLs and insert an
:func:`~django.conf.urls.defaults.include`, leaving you with::
:func:`~django.conf.urls.include`, leaving you with::
# This also imports the include function
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
:func:`~django.conf.urls.defaults.include` simply references another URLconf.
:func:`~django.conf.urls.include` simply references another URLconf.
Note that the regular expression doesn't have a ``$`` (end-of-string match
character) but has the trailing slash. Whenever Django encounters
:func:`~django.conf.urls.defaults.include`, it chops off whatever part of the
:func:`~django.conf.urls.include`, it chops off whatever part of the
URL matched up to that point and sends the remaining string to the included
URLconf for further processing.
@ -527,7 +527,7 @@ URLconf by removing the leading "polls/" from each line, and removing the
lines registering the admin site. Your ``polls/urls.py`` file should now look like
this::
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url
urlpatterns = patterns('polls.views',
(r'^$', 'index'),
@ -536,7 +536,7 @@ this::
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
The idea behind :func:`~django.conf.urls.defaults.include` and URLconf
The idea behind :func:`~django.conf.urls.include` and URLconf
decoupling is to make it easy to plug-and-play URLs. Now that polls are in their
own URLconf, they can be placed under "/polls/", or under "/fun_polls/", or
under "/content/polls/", or any other path root, and the app will still work.