django 单元测试报错: view must be a callable or a list/tuple in the case of include().

时间:2022-06-21 17:03:48

After upgrading to Django 1.10, I get the error:
TypeError: view must be a callable or a list/tuple in the case of include().
My urls.py is as follows:
urlpatterns = [
url(r’^$’, ‘lists.views.home_page’,name = ‘home_page’),
]

将superlists/superlists 中的urls.py 改成如下:

from django.conf.urls import url
from django.contrib import admin
from lists.views import home_page #必须加上

urlpatterns = [
url(r’^$’,home_page ,name=’home_page’) #加粗的部分不能用字符串
url(r’^admin/’, include(admin.site.urls)),
“urls.py” 24L, 859C

重新回到superlists目录下 执行Python manage.py test
测试通过

原因:
django 1.10之后不在支持URL用字符串表示了
http://*.com/questions/38744285/django-urls-error-view-must-be-a-callable-or-a-list-tuple-in-the-case-of-includ