Django + Zinnia:无法获取图像以便输入图示

时间:2015-01-18 19:13:47

标签: python django zinnia

我正在将zangnia博客(0.15.1)与Django(1.7.3)一起使用,而且我在渲染可以为博客条目添加的'插图图像'时出现问题。

我有以下urls.py文件:

我的top-dir url conf

# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
    url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
    url(r'^comments/', include('django_comments.urls')),
)

settins.py文件:

# -*- coding: utf-8 -*-
** Snip**
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True

# For using django.contrib.sites
SITE_ID = 2
# Application definition
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pro',
    'extended_cv',
    'zinnia', # Added for zinnia blog usage
    'django.contrib.sites',# Added for zinnia blog usage
    'django_comments',# Added for zinnia blog usage
    'mptt',# Added for zinnia blog usage
    'tagging',# Added for zinnia blog usage
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = ( 
    'django.contrib.auth.context_processors.auth', 
    'django.core.context_processors.i18n',
    'django.core.context_processors.request', 
    'zinnia.context_processors.version',  
)
** Snip**
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'

当我使用管理界面创建百日草的条目时,当我添加图像时,不会出现任何错误,并且新条目将保存到数据库而不会发出警告。然后,图像显示在地址 TopDir / upload / zinnia / date / of / publication / index_IKd2N0d.jpeg

的服务器树文件中

但是,当我从weblog应用程序中读取新条目时,我正确地看到了新条目,但没有看到图像。而且,服务器输出以下错误: GET /weblog/2015/01/18/1st-entry/uploads/zinnia/2015/01/18/index_IKd2N0d.jpeg HTTP / 1.1“404 8922

我想这个问题很难调试,如果你需要更多信息,我很乐意给你更多。

谢谢。

1 个答案:

答案 0 :(得分:0)

正如Daniel Roseman在评论中解释的那样,答案在于定义变量MEDIA_URL和MEDIA_ROOT,并重写顶部urls.py文件,如https://docs.djangoproject.com/en/1.7/howto/static-files/#serving-files-uploaded-by-a-user-during-development中所述:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
    url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
    url(r'^comments/', include('django_comments.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

工作已经完成。