Django弃用警告或错误配置错误 - 不支持将3元组传递给django.conf.urls.include()

时间:2017-04-10 13:06:48

标签: python django

我在Django 1.11中有一个弃用警告:

RemovedInDjango20Warning: Passing a 3-tuple to django.conf.urls.include() is deprecated. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.
  url(r'^admin/', include(admin.site.urls))

在Django 2.0中,这给出了错误:

django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. 
Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

我应该如何更改url(r'^admin/', include(admin.site.urls))?我试着查看文档,但我不知道......

这是我的urls.py:

from django.conf.urls import include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^admin/django-ses/', include('django_ses.urls')),
    url(r'^api/1.0/', include('feedcrunch_api_v1.urls')),
    url(r'^oauth/', include('oauth.urls')),
    url(r'^@(?P<feedname>\w+)/admin/', include('feedcrunch_rssadmin.urls')),
    url(r'^@(?P<feedname>\w+)/', include('feedcrunch_rssviewer.urls')),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'', include('feedcrunch_home.urls')),
]

2 个答案:

答案 0 :(得分:66)

自Django 1.9起,the old way of including the admin urls is deprecated。您应该admin.site.urls直接转到url(),而无需拨打include()

from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    ...
]

答案 1 :(得分:0)

我在Macbook上为此苦苦挣扎。我安装了Django 2.0并激活了一个虚拟环境。但是django-admin仍指向旧版本django的系统级安装。我的解决方案是卸载系统级django。之后,django-admin指向了较新的virtualenv版本。