Permalink
Browse files

Fixed #14675 -- Completed removal of `from django.conf.urls.default i…

…mport *` 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
  • Loading branch information...
1 parent fd90453 commit 26b812208751edf87b4df0aee00996c5c7bcd4c9 @ramiro ramiro committed Sep 11, 2011
Showing with 243 additions and 198 deletions.
  1. +1 −1 django/conf/project_template/urls.py
  2. +61 −0 django/conf/urls/__init__.py
  3. +5 −60 django/conf/urls/defaults.py
  4. +1 −1 django/conf/urls/i18n.py
  5. +1 −1 django/conf/urls/shortcut.py
  6. +1 −1 django/conf/urls/static.py
  7. +1 −1 django/contrib/admin/options.py
  8. +2 −2 django/contrib/admin/sites.py
  9. +1 −1 django/contrib/admindocs/urls.py
  10. +1 −1 django/contrib/auth/admin.py
  11. +1 −1 django/contrib/auth/tests/urls.py
  12. +1 −1 django/contrib/auth/urls.py
  13. +1 −1 django/contrib/comments/urls.py
  14. +1 −1 django/contrib/databrowse/urls.py
  15. +1 −1 django/contrib/flatpages/tests/urls.py
  16. +1 −1 django/contrib/flatpages/urls.py
  17. +1 −1 django/contrib/formtools/tests/urls.py
  18. +1 −1 django/contrib/formtools/tests/wizard/namedwizardtests/urls.py
  19. +1 −1 django/contrib/formtools/tests/wizard/wizardtests/urls.py
  20. +1 −1 django/contrib/gis/tests/geoadmin/urls.py
  21. +1 −1 django/contrib/gis/tests/geoapp/urls.py
  22. +1 −1 django/contrib/messages/tests/urls.py
  23. +1 −1 django/contrib/sitemaps/tests/urls.py
  24. +6 −0 docs/internals/deprecation.txt
  25. +1 −1 docs/intro/overview.txt
  26. +1 −1 docs/intro/tutorial02.txt
  27. +15 −15 docs/intro/tutorial03.txt
  28. +5 −5 docs/intro/tutorial04.txt
  29. +3 −3 docs/ref/contrib/admin/index.txt
  30. +2 −2 docs/ref/contrib/comments/example.txt
  31. +3 −3 docs/ref/contrib/formtools/form-wizard.txt
  32. +1 −1 docs/ref/contrib/gis/tutorial.txt
  33. +1 −1 docs/ref/contrib/sitemaps.txt
  34. +2 −2 docs/ref/contrib/syndication.txt
  35. +1 −1 docs/ref/models/instances.txt
  36. +14 −3 docs/releases/1.4.txt
  37. +3 −3 docs/topics/class-based-views.txt
  38. +3 −3 docs/topics/generic-views.txt
  39. +42 −19 docs/topics/http/urls.txt
  40. +3 −3 docs/topics/i18n/internationalization.txt
  41. +1 −1 tests/modeltests/test_client/urls.py
  42. +1 −1 tests/regressiontests/admin_views/customadmin.py
  43. +1 −1 tests/regressiontests/admin_views/urls.py
  44. +1 −2 tests/regressiontests/admin_widgets/urls.py
  45. +1 −1 tests/regressiontests/comment_tests/urls.py
  46. +1 −1 tests/regressiontests/comment_tests/urls_admin.py
  47. +1 −1 tests/regressiontests/conditional_processing/urls.py
  48. +1 −1 tests/regressiontests/context_processors/urls.py
  49. +1 −1 tests/regressiontests/file_uploads/urls.py
  50. +1 −1 tests/regressiontests/generic_inline_admin/urls.py
  51. +1 −1 tests/regressiontests/generic_views/urls.py
  52. +1 −1 tests/regressiontests/i18n/patterns/urls/default.py
  53. +1 −1 tests/regressiontests/i18n/patterns/urls/disabled.py
  54. +1 −1 tests/regressiontests/i18n/patterns/urls/namespace.py
  55. +1 −1 tests/regressiontests/i18n/patterns/urls/wrong.py
  56. +1 −1 tests/regressiontests/i18n/patterns/urls/wrong_namespace.py
  57. +1 −1 tests/regressiontests/middleware/cond_get_urls.py
  58. +1 −1 tests/regressiontests/middleware/extra_urls.py
  59. +1 −1 tests/regressiontests/middleware/urls.py
  60. +1 −1 tests/regressiontests/middleware_exceptions/urls.py
  61. +1 −1 tests/regressiontests/model_permalink/urls.py
  62. +1 −1 tests/regressiontests/special_headers/urls.py
  63. +1 −1 tests/regressiontests/staticfiles_tests/urls/default.py
  64. +1 −1 tests/regressiontests/syndication/urls.py
  65. +1 −1 tests/regressiontests/templates/alternate_urls.py
  66. +1 −1 tests/regressiontests/templates/urls.py
  67. +1 −1 tests/regressiontests/test_client_regress/urls.py
  68. +1 −1 tests/regressiontests/test_utils/urls.py
  69. +1 −1 tests/regressiontests/urlpatterns_reverse/erroneous_urls.py
  70. +1 −1 tests/regressiontests/urlpatterns_reverse/extra_urls.py
  71. +1 −1 tests/regressiontests/urlpatterns_reverse/included_named_urls.py
  72. +1 −1 tests/regressiontests/urlpatterns_reverse/included_named_urls2.py
  73. +1 −1 tests/regressiontests/urlpatterns_reverse/included_namespace_urls.py
  74. +1 −1 tests/regressiontests/urlpatterns_reverse/included_urls.py
  75. +1 −1 tests/regressiontests/urlpatterns_reverse/included_urls2.py
  76. +1 −1 tests/regressiontests/urlpatterns_reverse/named_urls.py
  77. +1 −1 tests/regressiontests/urlpatterns_reverse/namespace_urls.py
  78. +1 −1 tests/regressiontests/urlpatterns_reverse/no_urls.py
  79. +1 −1 tests/regressiontests/urlpatterns_reverse/reverse_lazy_urls.py
  80. +1 −1 tests/regressiontests/urlpatterns_reverse/urlconf_inner.py
  81. +1 −1 tests/regressiontests/urlpatterns_reverse/urlconf_outer.py
  82. +1 −1 tests/regressiontests/urlpatterns_reverse/urls.py
  83. +1 −1 tests/regressiontests/urlpatterns_reverse/urls_error_handlers.py
  84. +1 −1 tests/regressiontests/urlpatterns_reverse/urls_error_handlers_callables.py
  85. +2 −2 tests/regressiontests/urlpatterns_reverse/urls_without_full_import.py
  86. +1 −1 tests/regressiontests/views/generic_urls.py
  87. +1 −1 tests/regressiontests/views/urls.py
  88. +1 −1 tests/urls.py
@@ -1,4 +1,4 @@
-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
@@ -0,0 +1,61 @@
+from django.core.urlresolvers import (RegexURLPattern,
+ RegexURLResolver, LocaleRegexURLResolver)
+from django.core.exceptions import ImproperlyConfigured
+from django.utils.importlib import import_module
+
+
+__all__ = ['handler403', 'handler404', 'handler500', 'include', 'patterns', 'url']
+
+handler403 = 'django.views.defaults.permission_denied'
+handler404 = 'django.views.defaults.page_not_found'
+handler500 = 'django.views.defaults.server_error'
+
+def include(arg, namespace=None, app_name=None):
+ if isinstance(arg, tuple):
+ # callable returning a namespace hint
+ if namespace:
+ raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
+ urlconf_module, app_name, namespace = arg
+ else:
+ # No namespace hint - use manually provided namespace
+ urlconf_module = arg
+
+ if isinstance(urlconf_module, basestring):
+ urlconf_module = import_module(urlconf_module)
+ patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
+
+ # Make sure we can iterate through the patterns (without this, some
+ # testcases will break).
+ if isinstance(patterns, (list, tuple)):
+ for url_pattern in patterns:
+ # Test if the LocaleRegexURLResolver is used within the include;
+ # this should throw an error since this is not allowed!
+ if isinstance(url_pattern, LocaleRegexURLResolver):
+ raise ImproperlyConfigured(
+ 'Using i18n_patterns in an included URLconf is not allowed.')
+
+ return (urlconf_module, app_name, namespace)
+
+def patterns(prefix, *args):
+ pattern_list = []
+ for t in args:
+ if isinstance(t, (list, tuple)):
+ t = url(prefix=prefix, *t)
+ elif isinstance(t, RegexURLPattern):
+ t.add_prefix(prefix)
+ pattern_list.append(t)
+ return pattern_list
+
+def url(regex, view, kwargs=None, name=None, prefix=''):
+ if isinstance(view, (list,tuple)):
+ # For include(...) processing.
+ urlconf_module, app_name, namespace = view
+ return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
+ else:
+ if isinstance(view, basestring):
+ if not view:
+ raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex)
+ if prefix:
+ view = prefix + '.' + view
+ return RegexURLPattern(regex, view, kwargs, name)
+
@@ -1,61 +1,6 @@
-from django.core.urlresolvers import (RegexURLPattern,
- RegexURLResolver, LocaleRegexURLResolver)
-from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
-
-
-__all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
-
-handler403 = 'django.views.defaults.permission_denied'
-handler404 = 'django.views.defaults.page_not_found'
-handler500 = 'django.views.defaults.server_error'
-
-def include(arg, namespace=None, app_name=None):
- if isinstance(arg, tuple):
- # callable returning a namespace hint
- if namespace:
- raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
- urlconf_module, app_name, namespace = arg
- else:
- # No namespace hint - use manually provided namespace
- urlconf_module = arg
-
- if isinstance(urlconf_module, basestring):
- urlconf_module = import_module(urlconf_module)
- patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
-
- # Make sure we can iterate through the patterns (without this, some
- # testcases will break).
- if isinstance(patterns, (list, tuple)):
- for url_pattern in patterns:
- # Test if the LocaleRegexURLResolver is used within the include;
- # this should throw an error since this is not allowed!
- if isinstance(url_pattern, LocaleRegexURLResolver):
- raise ImproperlyConfigured(
- 'Using i18n_patterns in an included URLconf is not allowed.')
-
- return (urlconf_module, app_name, namespace)
-
-def patterns(prefix, *args):
- pattern_list = []
- for t in args:
- if isinstance(t, (list, tuple)):
- t = url(prefix=prefix, *t)
- elif isinstance(t, RegexURLPattern):
- t.add_prefix(prefix)
- pattern_list.append(t)
- return pattern_list
-
-def url(regex, view, kwargs=None, name=None, prefix=''):
- if isinstance(view, (list,tuple)):
- # For include(...) processing.
- urlconf_module, app_name, namespace = view
- return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
- else:
- if isinstance(view, basestring):
- if not view:
- raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex)
- if prefix:
- view = prefix + '.' + view
- return RegexURLPattern(regex, view, kwargs, name)
+import warnings
+warnings.warn("django.conf.urls.defaults is deprecated; use django.conf.urls instead",
+ PendingDeprecationWarning)
+from django.conf.urls import (handler403, handler404, handler500,
+ include, patterns, url)
@@ -1,5 +1,5 @@
from django.conf import settings
-from django.conf.urls.defaults import patterns
+from django.conf.urls import patterns
from django.core.urlresolvers import LocaleRegexURLResolver
def i18n_patterns(prefix, *args):
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
urlpatterns = patterns('django.views',
(r'^(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'defaults.shortcut'),
@@ -1,6 +1,6 @@
import re
from django.conf import settings
-from django.conf.urls.defaults import patterns, url
+from django.conf.urls import patterns, url
from django.core.exceptions import ImproperlyConfigured
def static(prefix, view='django.views.static.serve', **kwargs):
@@ -320,7 +320,7 @@ def __init__(self, model, admin_site):
super(ModelAdmin, self).__init__()
def get_urls(self):
- from django.conf.urls.defaults import patterns, url
+ from django.conf.urls import patterns, url
def wrap(view):
def wrapper(*args, **kwargs):
@@ -174,7 +174,7 @@ def admin_view(self, view, cacheable=False):
class MyAdminSite(AdminSite):
def get_urls(self):
- from django.conf.urls.defaults import patterns, url
+ from django.conf.urls import patterns, url
urls = super(MyAdminSite, self).get_urls()
urls += patterns('',
@@ -199,7 +199,7 @@ def inner(request, *args, **kwargs):
return update_wrapper(inner, view)
def get_urls(self):
- from django.conf.urls.defaults import patterns, url, include
+ from django.conf.urls import patterns, url, include
if settings.DEBUG:
self.check_dependencies()
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
from django.contrib.admindocs import views
urlpatterns = patterns('',
@@ -74,7 +74,7 @@ def get_form(self, request, obj=None, **kwargs):
return super(UserAdmin, self).get_form(request, obj, **defaults)
def get_urls(self):
- from django.conf.urls.defaults import patterns
+ from django.conf.urls import patterns
return patterns('',
(r'^(\d+)/password/$', self.admin_site.admin_view(self.user_change_password))
) + super(UserAdmin, self).get_urls()
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns, url
+from django.conf.urls import patterns, url
from django.contrib.auth import context_processors
from django.contrib.auth.urls import urlpatterns
from django.contrib.auth.views import password_reset
@@ -2,7 +2,7 @@
# provided as a convenience to those who want to deploy these URLs elsewhere.
# This file is also used to provide a reliable view deployment for test purposes.
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
urlpatterns = patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
urlpatterns = patterns('django.contrib.comments.views',
url(r'^post/$', 'comments.post_comment', name='comments-post-comment'),
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
from django.contrib.databrowse import views
# Note: The views in this URLconf all require a 'models' argument,
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, include
# special urls for flatpage test cases
urlpatterns = patterns('',
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
urlpatterns = patterns('django.contrib.flatpages.views',
(r'^(?P<url>.*)$', 'flatpage'),
@@ -2,7 +2,7 @@
This is a URLconf to be loaded by tests.py. Add any URLs needed for tests only.
"""
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
from django.contrib.formtools.tests import TestFormPreview, TestWizardClass
from forms import (ContactWizard, Page1, Page2, Page3, TestForm,
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns, url
+from django.conf.urls import patterns, url
from django.contrib.formtools.tests.wizard.namedwizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
from django.contrib.formtools.tests.wizard.wizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, include
from django.contrib import admin
urlpatterns = patterns('',
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
from feeds import feed_dict
urlpatterns = patterns('',
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
@@ -1,5 +1,5 @@
from datetime import datetime
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap
from django.contrib.auth.models import User
@@ -243,6 +243,12 @@ their deprecation, as per the :ref:`deprecation policy
:mod:`django.contrib.gis.geoip` in 1.4 -- the shortcut in
:mod:`django.contrib.gis.utils` will be removed.
+ * In 1.4, functions :func:`~django.conf.urls.include`, :func:`~django.conf.urls.patterns`
+ and :func:`~django.conf.urls.url` plus :data:`~django.conf.urls.handler404`,
+ :data:`~django.conf.urls.handler500` were moved to :mod:`django.conf.urls`
+ from their previous location ``django.conf.urls.defaults``. This module
+ was deprecated at the same time and will be removed in this Django release.
+
2.0
---
@@ -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**
Oops, something went wrong. Retry.

0 comments on commit 26b8122

Please sign in to comment.