我的settings.py
文件中有以下代码
MEDIA_ROOT_PATH = MEDIA_FILES = os.path.join(PROJECT_ROOT, "media")
MEDIA_ROOT = MEDIA_ROOT_PATH
MEDIA_URL = '/media/'
STATIC_ROOT_PATH = STATIC_FILES = os.path.join(PROJECT_ROOT, "static")
STATIC_ROOT = STATIC_ROOT_PATH
STATIC_URL = '/static/'
和urls.py
文件中的这一行
urlpatterns += staticfiles_urlpatterns()
开发服务器能够提供/static/
目录但不是/media/
目录中的内容,如何将其添加到urls.py?
答案 0 :(得分:1)
将以下内容添加到您的网址模式中:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))