diff options
| author | Tim Graham <timograham@gmail.com> | 2014-08-12 10:54:42 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-08-12 13:15:40 -0400 |
| commit | a9fd740d22bc4fed5fdb280c036618000ee13df1 (patch) | |
| tree | 18a58170b4633f22e5869db2c2ed086245ed415c /django | |
| parent | 2003cb23d4f1b3be717855d41b562d4d5cfebe99 (diff) | |
Fixed #23276 -- Deprecated passing views as strings to url().
Diffstat (limited to 'django')
| -rw-r--r-- | django/conf/urls/__init__.py | 6 | ||||
| -rw-r--r-- | django/conf/urls/i18n.py | 3 | ||||
| -rw-r--r-- | django/conf/urls/static.py | 3 | ||||
| -rw-r--r-- | django/contrib/auth/tests/urls.py | 32 | ||||
| -rw-r--r-- | django/contrib/staticfiles/urls.py | 3 | ||||
| -rw-r--r-- | django/contrib/staticfiles/views.py | 4 | ||||
| -rw-r--r-- | django/views/static.py | 4 |
7 files changed, 34 insertions, 21 deletions
diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py index 60c767fc9b..094b4cb3e8 100644 --- a/django/conf/urls/__init__.py +++ b/django/conf/urls/__init__.py @@ -67,6 +67,12 @@ def url(regex, view, kwargs=None, name=None, prefix=''): return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace) else: if isinstance(view, six.string_types): + warnings.warn( + 'Support for string view arguments to url() is deprecated and ' + 'will be removed in Django 2.0 (got %s). Pass the callable ' + 'instead.' % view, + RemovedInDjango20Warning, stacklevel=2 + ) if not view: raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex) if prefix: diff --git a/django/conf/urls/i18n.py b/django/conf/urls/i18n.py index 6e776a2ecd..9366a5f708 100644 --- a/django/conf/urls/i18n.py +++ b/django/conf/urls/i18n.py @@ -5,6 +5,7 @@ from django.conf.urls import patterns, url from django.core.urlresolvers import LocaleRegexURLResolver from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning +from django.views.i18n import set_language def i18n_patterns(prefix, *args): @@ -30,5 +31,5 @@ def i18n_patterns(prefix, *args): urlpatterns = [ - url(r'^setlang/$', 'django.views.i18n.set_language', name='set_language'), + url(r'^setlang/$', set_language, name='set_language'), ] diff --git a/django/conf/urls/static.py b/django/conf/urls/static.py index f3470af025..ab4270b0a5 100644 --- a/django/conf/urls/static.py +++ b/django/conf/urls/static.py @@ -3,9 +3,10 @@ import re from django.conf import settings from django.conf.urls import url from django.core.exceptions import ImproperlyConfigured +from django.views.static import serve -def static(prefix, view='django.views.static.serve', **kwargs): +def static(prefix, view=serve, **kwargs): """ Helper function to return a URL pattern for serving files in debug mode. diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py index 9997b29bbe..bad129cd5e 100644 --- a/django/contrib/auth/tests/urls.py +++ b/django/contrib/auth/tests/urls.py @@ -3,7 +3,7 @@ from django.contrib import admin from django.contrib.auth import context_processors from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.urls import urlpatterns -from django.contrib.auth.views import password_reset, login +from django.contrib.auth import views from django.contrib.auth.decorators import login_required from django.contrib.messages.api import info from django.http import HttpResponse, HttpRequest @@ -67,29 +67,29 @@ def userpage(request): def custom_request_auth_login(request): - return login(request, authentication_form=CustomRequestAuthenticationForm) + return views.login(request, authentication_form=CustomRequestAuthenticationForm) # special urls for auth test cases urlpatterns += [ - url(r'^logout/custom_query/$', 'django.contrib.auth.views.logout', dict(redirect_field_name='follow')), - url(r'^logout/next_page/$', 'django.contrib.auth.views.logout', dict(next_page='/somewhere/')), - url(r'^logout/next_page/named/$', 'django.contrib.auth.views.logout', dict(next_page='password_reset')), + url(r'^logout/custom_query/$', views.logout, dict(redirect_field_name='follow')), + url(r'^logout/next_page/$', views.logout, dict(next_page='/somewhere/')), + url(r'^logout/next_page/named/$', views.logout, dict(next_page='password_reset')), url(r'^remote_user/$', remote_user_auth_view), - url(r'^password_reset_from_email/$', 'django.contrib.auth.views.password_reset', dict(from_email='staffmember@example.com')), - url(r'^password_reset/custom_redirect/$', 'django.contrib.auth.views.password_reset', dict(post_reset_redirect='/custom/')), - url(r'^password_reset/custom_redirect/named/$', 'django.contrib.auth.views.password_reset', dict(post_reset_redirect='password_reset')), - url(r'^password_reset/html_email_template/$', 'django.contrib.auth.views.password_reset', dict(html_email_template_name='registration/html_password_reset_email.html')), + url(r'^password_reset_from_email/$', views.password_reset, dict(from_email='staffmember@example.com')), + url(r'^password_reset/custom_redirect/$', views.password_reset, dict(post_reset_redirect='/custom/')), + url(r'^password_reset/custom_redirect/named/$', views.password_reset, dict(post_reset_redirect='password_reset')), + url(r'^password_reset/html_email_template/$', views.password_reset, dict(html_email_template_name='registration/html_password_reset_email.html')), url(r'^reset/custom/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', - 'django.contrib.auth.views.password_reset_confirm', + views.password_reset_confirm, dict(post_reset_redirect='/custom/')), url(r'^reset/custom/named/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', - 'django.contrib.auth.views.password_reset_confirm', + views.password_reset_confirm, dict(post_reset_redirect='password_reset')), - url(r'^password_change/custom/$', 'django.contrib.auth.views.password_change', dict(post_change_redirect='/custom/')), - url(r'^password_change/custom/named/$', 'django.contrib.auth.views.password_change', dict(post_change_redirect='password_reset')), - url(r'^admin_password_reset/$', 'django.contrib.auth.views.password_reset', dict(is_admin_site=True)), - url(r'^login_required/$', login_required(password_reset)), - url(r'^login_required_login_url/$', login_required(password_reset, login_url='/somewhere/')), + url(r'^password_change/custom/$', views.password_change, dict(post_change_redirect='/custom/')), + url(r'^password_change/custom/named/$', views.password_change, dict(post_change_redirect='password_reset')), + url(r'^admin_password_reset/$', views.password_reset, dict(is_admin_site=True)), + url(r'^login_required/$', login_required(views.password_reset)), + url(r'^login_required_login_url/$', login_required(views.password_reset, login_url='/somewhere/')), url(r'^auth_processor_no_attr_access/$', auth_processor_no_attr_access), url(r'^auth_processor_attr_access/$', auth_processor_attr_access), diff --git a/django/contrib/staticfiles/urls.py b/django/contrib/staticfiles/urls.py index 4a0feeaaf8..5f27f4f14d 100644 --- a/django/contrib/staticfiles/urls.py +++ b/django/contrib/staticfiles/urls.py @@ -1,5 +1,6 @@ from django.conf import settings from django.conf.urls.static import static +from django.contrib.staticfiles.views import serve urlpatterns = [] @@ -10,7 +11,7 @@ def staticfiles_urlpatterns(prefix=None): """ if prefix is None: prefix = settings.STATIC_URL - return static(prefix, view='django.contrib.staticfiles.views.serve') + return static(prefix, view=serve) # Only append if urlpatterns are empty if settings.DEBUG and not urlpatterns: diff --git a/django/contrib/staticfiles/views.py b/django/contrib/staticfiles/views.py index 5312de2931..166879a0e5 100644 --- a/django/contrib/staticfiles/views.py +++ b/django/contrib/staticfiles/views.py @@ -21,7 +21,9 @@ def serve(request, path, insecure=False, **kwargs): To use, put a URL pattern such as:: - (r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve') + from django.contrib.staticfiles import views + + url(r'^(?P<path>.*)$', views.serve) in your URLconf. diff --git a/django/views/static.py b/django/views/static.py index 68fb7c4654..2998688284 100644 --- a/django/views/static.py +++ b/django/views/static.py @@ -24,7 +24,9 @@ def serve(request, path, document_root=None, show_indexes=False): To use, put a URL pattern such as:: - (r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/my/files/'}) + from django.views.static import serve + + url(r'^(?P<path>.*)$', serve, {'document_root': '/path/to/my/files/'}) in your URLconf. You must provide the ``document_root`` param. You may also set ``show_indexes`` to ``True`` if you'd like to serve a basic index |
