2 django django-rest-framework
我试图通过网络浏览器/ DRF可浏览的API查看我上传的图像.所以我说MEDIA_URL和MEDIA_ROOT我setting.py文件.当我试图运行代码时,它显示出来 TypeError: static() got an unexpected keyword argument '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/'
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
小智 9
此错误是由于您导入错误的静态引用.尝试使用from django.conf.urls.static import static而不是from django.templatetags.static import static
| 归档时间: |
|
| 查看次数: |
1016 次 |
| 最近记录: |