2017-01-20 113 views
3

我想通過web瀏覽器/ DRF瀏覽器API查看我上傳的圖片。所以我添加了MEDIA_URLMEDIA_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) 

回答

5

你是進口的錯誤此錯誤是由於靜態的參考文獻。嘗試o使用from django.conf.urls.static import static代替from django.templatetags.static import static

相關問題