contrib.staticfiles settings suggestion

10 views
Skip to first unread message

Ryan

unread,
Oct 31, 2010, 6:06:34 PM10/31/10
to Django developers
I track trunk while developing new projects, and I just picked up the
new contrib.staticfiles app. I was disappointed how repetitive and
redundant the configuration is. I already have MEDIA_ROOT and
MEDIA_URL defined, so now I have to add

STATICFILES_ROOT = MEDIA_ROOT
STATICFILES_URL = MEDIA_URL
STATICFILES_DIRS = (STATICFILES_ROOT,)

just to get things back working like before. What is the purpose of
having both MEDIA_* *and* STATICFILES_* settings? Don't they mean the
same thing? If there's a good reason to have all these settings, can
we not have the settings I had to enter above as defaults, similar to
how MANAGERS = ADMINS by default?

Thanks,
Ryan

Issac Kelly

unread,
Oct 31, 2010, 6:32:31 PM10/31/10
to django-d...@googlegroups.com
I've been a staticfiles user for a while, let me explain my normal setup, and one where it's a bit more complicated.

PROJECT_ROOT = /path/to/project
MEDIA_ROOT = PROJECT_ROOT/site_media/media
STATICFILES_ROOT = PROJECT_ROOT/sitemedia/static

PROJECT_STATIC (not an actual setting) = PROJECT_ROOT/static (gets put in STATICFILES_ROOT on build)

This way, uploaded content is separate from in-repository static media,
and in-repo static media is separate from in-production static media

I also have a project that uses the sites framework extensively, they all have independent STATIC_ settings, but share a group of MEDIA_ settings, as uploaded content is shared across sites, but static content (JS and CSS) is independent per site.

Hope this helps
Issac



--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.


Jannis Leidel

unread,
Nov 3, 2010, 5:12:22 AM11/3/10
to django-d...@googlegroups.com
On 31.10.2010, at 23:06, Ryan wrote:

> I track trunk while developing new projects, and I just picked up the
> new contrib.staticfiles app. I was disappointed how repetitive and
> redundant the configuration is. I already have MEDIA_ROOT and
> MEDIA_URL defined, so now I have to add
>
> STATICFILES_ROOT = MEDIA_ROOT
> STATICFILES_URL = MEDIA_URL
> STATICFILES_DIRS = (STATICFILES_ROOT,)

Please refer to the documentation for a description of those settings.

> just to get things back working like before. What is the purpose of
> having both MEDIA_* *and* STATICFILES_* settings? Don't they mean the
> same thing? If there's a good reason to have all these settings, can
> we not have the settings I had to enter above as defaults, similar to
> how MANAGERS = ADMINS by default?

No, MEDIA_* and STATICFILES_* settings aren't the same, the former is for user generated content (like file uploads), the latter for general static files your site needs to work (such as css/js files). The distinction is also well described in the dev documentation.

Jannis

Brian Neal

unread,
Nov 3, 2010, 7:55:58 PM11/3/10
to Django developers
On Nov 3, 4:12 am, Jannis Leidel <jan...@leidel.info> wrote:
>
> No, MEDIA_* and STATICFILES_* settings aren't the same, the former is for user generated content (like file uploads), the latter for general static files your site needs to work (such as css/js files). The distinction is also well described in the dev documentation.
>

Where is this distinction in the docs? I read over the staticfiles
documentation trying to figure out how it related to MEDIA_* and it
was not clear to me. I think the docs need some improving to explain
the purpose of this app and the problem it is trying to solve
(separation of user uploaded media and app media). It just kind of
landed in trunk. It wasn't obvious to me, for example, that the dev
server would continue to serve media in MEDIA_ROOT or if I had to add
MEDIA_ROOT to STATICFILES_DIRS and enable the FileSystemFinder. I
realize it might be too early for release notes, but that would be
helpful for me at least.

I'd be glad to help, but I'm still trying to figure it out. I'll try
to write a blog post or a doc patch.

Thanks,
BN

Jannis Leidel

unread,
Nov 4, 2010, 4:06:15 AM11/4/10
to django-d...@googlegroups.com
On 04.11.2010, at 00:55, Brian Neal wrote:

> On Nov 3, 4:12 am, Jannis Leidel <jan...@leidel.info> wrote:
>>
>> No, MEDIA_* and STATICFILES_* settings aren't the same, the former is for user generated content (like file uploads), the latter for general static files your site needs to work (such as css/js files). The distinction is also well described in the dev documentation.
>
> Where is this distinction in the docs? I read over the staticfiles
> documentation trying to figure out how it related to MEDIA_* and it
> was not clear to me. I think the docs need some improving to explain
> the purpose of this app and the problem it is trying to solve
> (separation of user uploaded media and app media). It just kind of
> landed in trunk. It wasn't obvious to me, for example, that the dev
> server would continue to serve media in MEDIA_ROOT or if I had to add
> MEDIA_ROOT to STATICFILES_DIRS and enable the FileSystemFinder. I
> realize it might be too early for release notes, but that would be
> helpful for me at least.

Ok, thanks for your input, would you mind creating a ticket describing the discrepancy in more detail? I thought the how to [1] explains enough of purpose of the app, so any further input would be much appreciated.

> I'd be glad to help, but I'm still trying to figure it out. I'll try
> to write a blog post or a doc patch.

If you could specify what can't be understood it'd be easier to extend the docs, indeed.


Jannis

1: http://docs.djangoproject.com/en/dev/howto/static-files/

Brian Neal

unread,
Nov 4, 2010, 2:38:36 PM11/4/10
to Django developers
On Nov 4, 3:06 am, Jannis Leidel <jan...@leidel.info> wrote:
> Ok, thanks for your input, would you mind creating a ticket describing the discrepancy in more detail? I thought the how to [1] explains enough of purpose of the app, so any further input would be much appreciated.
>
> > I'd be glad to help, but I'm still trying to figure it out. I'll try
> > to write a blog post or a doc patch.
>
> If you could specify what can't be understood it'd be easier to extend the docs, indeed.
>
> Jannis
>
> 1:http://docs.djangoproject.com/en/dev/howto/static-files/

I guess the complete absence of a discussion of MEDIA_* from the link
you posted is what threw me at first. Upon first impression, one might
think that MEDIA_URL and MEDIA_ROOT are gone. But of course they are
not. I guess what would be helpful would be a guide on how to migrate
to staticfiles; some release notes I guess. If you were someone who
was just stashing your application's CSS and Javascript in some spot
under your MEDIA_ROOT, what is best way to migrate to staticfiles, and
what changes, if any, need to be done to keep the devserver serving
the MEDIA_* files? I can piece it together from the docs now after
reading it a few times. Maybe a tutorial or release notes would be
good. I'm not sure if that belongs in your docs though. I'll think
about it some more.
Reply all
Reply to author
Forward
0 new messages