mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
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:
@@ -176,7 +176,7 @@ decouple URLs from Python code.
|
||||
Here's what a URLconf might look like for the ``Reporter``/``Article``
|
||||
example above::
|
||||
|
||||
from django.conf.urls.defaults import *
|
||||
from django.conf.urls import patterns, url, include
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
|
||||
|
||||
@@ -40,7 +40,7 @@ activate the admin site for your installation, do these three things:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
**from django.contrib import admin**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -218,7 +218,7 @@ Read on for details.
|
||||
First, open the ``polls/urls.py`` URLconf. It looks like this, according to the
|
||||
tutorial so far::
|
||||
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
urlpatterns = patterns('polls.views',
|
||||
(r'^$', 'index'),
|
||||
@@ -229,7 +229,7 @@ tutorial so far::
|
||||
|
||||
Change it like so::
|
||||
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.views.generic import DetailView, ListView
|
||||
from polls.models import Poll
|
||||
|
||||
@@ -269,9 +269,9 @@ two views abstract the concepts of "display a list of objects" and
|
||||
that we have a way to refer to its URL later on (see the
|
||||
documentation about :ref:`naming URL patterns
|
||||
<naming-url-patterns>` for information). We're also using the
|
||||
:func:`~django.conf.urls.default.url` function from
|
||||
:mod:`django.conf.urls.defaults` here. It's a good habit to use
|
||||
:func:`~django.conf.urls.defaults.url` when you are providing a
|
||||
:func:`~django.conf.urls.url` function from
|
||||
:mod:`django.conf.urls` here. It's a good habit to use
|
||||
:func:`~django.conf.urls.url` when you are providing a
|
||||
pattern name like this.
|
||||
|
||||
By default, the :class:`~django.views.generic.list.DetailView` generic
|
||||
|
||||
Reference in New Issue
Block a user