3
我想通过web浏览器/ DRF浏览器API查看我上传的图片。所以我添加了MEDIA_URL
和MEDIA_ROOT
到我的setting.py文件。当我尝试运行代码时,它显示TypeError: static() got an unexpected keyword argument 'document_root'
。
这是我的代码的相关部分,Django:TypeError:static()得到了一个意外的关键字参数'document_root'
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR,'Images')
MEDIA_URL = '/Images/'
urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.templatetags.static import static
urlpatterns = [
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^$', index),
url(r'^health$', health),
url(r'^admin/', include(admin.site.urls)),
url(r'^sample/',sampelview),
url(r'myapp/',include(myRouter.urls)),
url(r'^test/$', testRequest),
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)