Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django 1.9在生产中提供媒体文件_Django - Fatal编程技术网

django 1.9在生产中提供媒体文件

django 1.9在生产中提供媒体文件,django,Django,我现在切换到django 1.9(从1.8.4版开始),我的媒体文件停止了 待送达。。i、 e.用户上传的每个文件都不会在 模板-未显示图像,无法下载下载的文件 有什么问题吗 设置: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, 'DIRS': [ # insert you

我现在切换到django 1.9(从1.8.4版开始),我的媒体文件停止了

待送达。。i、 e.用户上传的每个文件都不会在

模板-未显示图像,无法下载下载的文件

有什么问题吗

设置:

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/'
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 网址:

模板:

<img src="{{ obj.image.url }}" height="30%" width="25%">

这对我很有用(django 1.9.1)

在设置中: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 媒体URL='/MEDIA/' MEDIA\u ROOT=os.path.join(基本目录'MEDIA') 在URL中: 如果设置为.DEBUG: 从django.conf.url.static导入静态 urlpatterns+=静态(settings.MEDIA\u URL, document\u root=settings.MEDIA\u root)

既然您应该知道Django在生产环境中没有(也从来没有)为静态文件提供服务,为什么要发布URL?相反,您应该发布您的Web服务器配置。它在开发中也不起作用。。它过去也在生产中使用。。 if settings.DEBUG: from django.conf.urls.static import static urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)