On 01/01/13 18:28, Aymeric Augustin wrote:

> There are two special cases that don't fit into apps: STATIC_ROOT and
> MEDIA_ROOT. (Technically, there's ALLOWED_INCLUDE_ROOTS too, but it
> isn't commonly used.)
> 
> Static files are collected from the apps into STATIC_ROOT that is
> then served by the web server. To avoid accidentally leaking Python
> code over the web, it's a good idea to keep this directory outside of
> your source tree.
> 
> Media files are written by the application server into MEDIA_ROOT.
> It's a good idea to put them on a separate partition (DoS by filling
> up / isn't fun), or at least in a directory outside of your source
> tree, which must be read-only for the web server.
> 
> For local development, it's certainly fine to store the code in
> /home/myproject, compile the static files in /home/myproject/static,
> and uploading the media files in /home/myproject/media, and it's
> convenient to express that with relative paths. But it's hardly a
> best practice in production — at least, not until you've spent 30
> seconds thinking about it.

You are assuming here that use of relative paths and PROJECT_ROOT for
media implies that you are putting your MEDIA_ROOT/STATIC_ROOT *inside*
PROJECT_ROOT. But you don't have to.

I often have the situation where I have multiple copies of a project on
a machine - often 'staging' and 'production' on the same machine (e.g.
shared hosting), and also for other reasons.  I have a layout something
like:


/home
  /myuser
    /apps
      /foo_staging
        /src
        /static
        /media
      /foo_production
        /src
        /media
        /static

/src is PROJECT_ROOT, and STATIC_ROOT and MEDIA_ROOT will be calculated
relative to that. This system makes projects completely relocatable, and
is a good use case for PROJECT_ROOT IMO.

However, this isn't something that you could put into a default
settings.py, because it assumes things about directory structure outside
the project sources.

Common opinion amongst core devs seems to be against PROJECT_ROOT. If we
are consistent about that, we ought to be thinking about deprecating
TEMPLATE_DIRS, STATICFILES_DIRS,
django.template.loaders.filesystem.Loader,
django.contrib.staticfiles.finders.FileSystemFinder
etc., as mentioned by Shai.


Luke

-- 
 A mosquito cried out in pain:
 "A chemist has poisoned my brain!"
 The cause of his sorrow
 was para-dichloro-
 diphenyltrichloroethane

Luke Plant || http://lukeplant.me.uk/

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

Reply via email to