pythondjangozinnia

Django + Zinnia: Can not GET image for entry's illustration


I'm using Django (1.7.3) with zinnia blog (0.15.1) and I'm having an issue for rendering the 'image for illustration' that you can add for a blog entry.

I have the following urls.py files:

My 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')),
)

The settins.py file:

# -*- 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/'

When I create an entry for zinnia using admin UI, and when I add an image, no error appear, and the new entry is saved to database with no warning. The image then appear in the server tree file at the adress TopDir/upload/zinnia/date/of/publication/index_IKd2N0d.jpeg

But, when I read the new entry from the weblog app, I correctly see the new entry, but not the image. Moreover, the server output the following error: GET /weblog/2015/01/18/1st-entry/uploads/zinnia/2015/01/18/index_IKd2N0d.jpeg HTTP/1.1" 404 8922

I guess the issue is kind of complicated to debug, then if you need more information, I'll be happy to give you more.

Thank you.


Solution

  • As explain by Daniel Roseman in the comments, the answer consists into defining the variables MEDIA_URL and MEDIA_ROOT, and to rewrite the top urls.py file as explained in 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)
    

    And the work is done.