在django 3.0上提供包含()的命名空间参数
在Django 3.0中,会出现以下错误:在django 3.0上提供包含()的命名空间参数,django,python-3.7,Django,Python 3.7,在Django 3.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'^a
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.url))
?我试着看文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^hello/', include(myapp.views)),
]
从管理员URL中删除include并使用路径
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', include('myapp.views')),
]
请参阅此问题在于
包含(myapp.views)
:
- 首先,您应该包括一个字符串(
),而不是实际的模块。这就是导致错误的原因include('myapp.views')
- 但第二,您不包括视图,而是包括其他url模式。因此,除非
包含顶级myapp.views
,否则您也会得到一个错误urlpatterns
最后,正如@c.grey指出的,使用
path()
,而不是url()
包含的include()
?与admin
相同,它应该include()
。使用path
或re_path
,从django.url
导入它们。你看了哪些文件?不再有url
。