Django弃用警告或配置不正确的错误-不支持将3元组传递给django.conf.urls.include() [英] Django Deprecation Warning or ImproperlyConfigured error - Passing a 3-tuple to django.conf.urls.include() is not supported

查看:172
本文介绍了Django弃用警告或配置不正确的错误-不支持将3元组传递给django.conf.urls.include()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django 1.11中有弃用警告:

I have a deprecation warning in 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中,出现错误:

In Django 2.0 this gives the error:

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))?我试图看一下文档,但不知道...

How should I change url(r'^admin/', include(admin.site.urls))? I tried to look at the documentation, but I have no clue ...

这是我的urls.py:

Here is my 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')),
]


推荐答案

从Django 1.9开始,不推荐使用包含管理url的旧方法。您应该直接将 admin.site.urls 传递给 url(),而无需调用 include()

As of Django 1.9, the old way of including the admin urls is deprecated. You should pass admin.site.urls directly to url(), without the call to include():

from django.contrib import admin

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

这篇关于Django弃用警告或配置不正确的错误-不支持将3元组传递给django.conf.urls.include()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆