On Tue, 25 Jan 2011 21:46:39 -0800 (PST)
Brian Neal <bgn...@gmail.com> wrote:

Hiya,

> I'm trying to cut over my project to use the new staticfiles
> application. I'm using the dev server with DEBUG = True on a recent
> SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is
> 'http://localhost:8000/media/' in this environment.

I'm in a similar boat...trying (again) with Django-1.3

> Eventually I came to the conclusion that I had do this:
> 
> urls.py:
> if settings.DEBUG:
>    urlpatterns += patterns('django.contrib.staticfiles.views',
>       (r'^media/(?P<path>.*)$', 'serve', {'document_root':
> settings.MEDIA_ROOT}),
>    )

My project is at ~/home/gour/www/zinnia in virtual env.

Zinnia (blog engine) media files are symlinked to:

/usr/home/gour/www/zinnia/lib/python2.7/site-packages/zinnia/media/zinnia --> 
/usr/home/gour/www/zinnia/blog/static

and in order to see media files I've the following in my settings.py:

[...]

PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

MEDIA_ROOT = os.path.join(PROJECT_PATH, "static")

MEDIA_URL = '/media/'

ADMIN_MEDIA_PREFIX = '/media/admin/'

[...]

and here is the snippet from urls.py:

from django.conf import settings

if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
   )

The above snippet is from dev-docs, while the 1.3 doc says:

from django.conf import settings

if settings.DEBUG:
    urlpatterns += patterns('django.contrib.staticfiles.views',
        url(r'^static/(?P<path>.*)$', 'serve'),
    )


Now I'm told on #django that this is obsolete and from 1.3 one is supposed to
use:

django.contrib.staticfiles 

and I tried to add it to INSTALLED_APPS, defined STATIC_ROOT, STATIC_URL,
STATICFILES_DIRS..and adding:

urlpatterns += staticfiles_urlpatterns() to urls.py, but all what I get is 404 
errors.

> The docs don't seem to mention using this view for this purpose.
> Should they?

This is my confusion as well. The doc says:

<quote>
This view is automatically enabled by runserver (with a DEBUG setting set to
True). To use the view with a different local development server, add the
following snippet to the end of your primary URL configuration:

from django.conf import settings

if settings.DEBUG:
    urlpatterns += patterns('django.contrib.staticfiles.views',
        url(r'^static/(?P<path>.*)$', 'serve'),
    )

</quote>

and based on the avove it seems that if one just wants to use runserver there
should not be need for the django.contrib.staticfiles.views view, but, based on
my experience I was not able to render media files without using the above
snippet in urls.py, so my humgble request is whether someone can provide
correct info how to serve app's media (static) files in django-1.3 when using
runserver in development?


Sincerely,
Gour


-- 
“In the material world, conceptions of good and bad are
all mental speculations…” (Sri Caitanya Mahaprabhu)

http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810


Attachment: signature.asc
Description: PGP signature

Reply via email to