3
媒體文件,目前我切換到Django的1.9(從1.8.4)和我的媒體文件採空的Django 1.9服務於生產
送達..即由用戶上傳中沒有提供的所有文件在
模板 - 圖像不顯示和下載的文件不能下載..
可能是什麼問題?
設置:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media/')
MEDIA_URL = '/media/'
網址:
urlpatterns = [...] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT) + \
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
模板:
<img src="{{ obj.image.url }}" height="30%" width="25%">
你爲什麼要張貼您的網址,因爲你應該知道,Django的不(和從來沒有)生產服務的靜態文件本身?相反,你應該發佈你的網絡服務器配置。 –
它也沒有在開發中工作..它也用於生產工作.. – brad