Django的urls.py加载静态资源图片,TypeError: view must be a callable or a list/tuple in the case of include().

时间:2021-05-27 12:29:44

Django的urls.py加载静态资源图片,TypeError: view must be a callable or a list/tuple in the case of include().

想直接显示图片,加个静态的地址,查了许多网上资料。写进去后报错:TypeError: view must be a callable or a list/tuple in the case of include().

就是下面这段代码

 url(r'^images/(?P<path>.*)$',  serve, {'document_root': os.path.join( STATIC_ROOT , 'images' )}),

django1.10不再支持上面这种写法,正确的写法如下

from django.views.static import serve
url(r'^images/(?P<path>.*)$', serve, {'document_root': os.path.join( STATIC_ROOT , 'images/' )}),

记下给自己和朋友提个醒。