I would like to see support for relative paths. It seems the solution is simple, but I wonder if there is some compelling reason to require absolute paths?
Computing the root of your project with os.path works just fine and doesn't require another setting... which, btw, could have no sane default.
On 29/12/12 04:08, Cal Leeming [Simplicity Media Ltd] wrote:For consistency, we'd need STATICFILES_PATH_RELATIVE,
> Could we not have something like this in the settings.py, which in turn
> enabled the code pasted above?
> TEMPLATE_PATH_RELATIVE=True
STATIC_ROOT_PATH_RELATIVE, MEDIA_ROOT_PATH_RELATIVE etc. which is
craziness. Having just one extra setting is a big deal.
There are use cases for all of these being absolute paths (or at least
some of them), and use cases for all of them being relative. We've
already chosen absolute paths, and you can generate absolute from
relative using os.path.realpath etc.
The only option I can is whether we put that snippet of code (e.g.
PROJECT_ROOT=os.path.realpath(os.path.dirname(__file__)) ) into the
settings file generated when starting a new project.
Luke
--
"If we could just get everyone to close their eyes and visualise
world peace for an hour, imagine how serene and quiet it would be
until the looting started" -- Anon
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
Rather than saying "spend 30 seconds thinking about it", could you perhaps spend 30 seconds explaining why using relative paths for TEMPLATE_DIRS would be considered a bad thing to do?
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/xuVeOmwI_8AJ.
A modern Django project is a collection of apps. Files are looked up under conventional paths within apps. Modules (especially the settings module) can live anywhere on $PYTHONPATH. Actually, there's not such thing as a project root.
For instance, instead of using TEMPLATE_DIRS, project-wide templates can go into an "myproject" application. You need one anyway as soon as you write a custom template tag or filter.
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.)
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.
Django leaves it up to the developer to structure the settings for different environments. This means we cannot provide a "development only" settings template.
FWIW, this is a working draft of a default settings file I like that addresses most of these issues: https://github.com/tedtieken/django-project-skel/blob/master/project_name/settings.py (would appreciate constructive criticism offline)
Florian, the method you use for environment specific settings is one of the two most common I saw in my survey: local_settings.py being the most common. Again, best practice vs common practice I don't know.
But again, I'm not proposing my settings.py file as the default, just provided for context.
* local_settings is imo a bad pattern as they can't easily override anything without copying it completely into the local_settings (think of all the settings which are dicts like DATABASES and CACHES)