Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » De-coupling settings.py from project [RSS Feed]

#1 Dec. 30, 2010 16:52:41

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

De-coupling settings.py from project


I'm new to Django and trying to create an office intranet web service.
Because I value pragmatic programming, I want to take the time to 'do
it right' and so I'm spending as much time as possible de-coupling the
'django application' from the 'django project' (or 'django site' -
these seem to be synonyms.)

To that end, I've managed to de-couple the urls.py file by using the
url importing system, and the templates by using a template loader.
However, a few settings seem to be impossible to de-couple from the
project to the application.

In particular, I'm having trouble specifying the static content URL
and the fixtures directories at a per-application level rather than in
the project settings.py file.

Is there a way to specify settings like STATIC_URL or FIXTURES_DIRS
per-application rather than per-site? Even better - is there a
mechanism to use a settings.py file in the application rather than in
the site?

Thanks,
eblume

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

Offline

#2 Dec. 30, 2010 18:10:12

Christophe P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

De-coupling settings.py from project


On Dec 30, 2010, at 8:50 AM, eblume wrote:
> Is there a way to specify settings like STATIC_URL or FIXTURES_DIRS
> per-application rather than per-site? Even better - is there a
> mechanism to use a settings.py file in the application rather than in
> the site?

I think that your overall goal is quite admirable, but this may be an
optimization too far. One way to think of the way Django organizes its code is
that a project is the platform on which applications are deployed. The role of
settings.py (and the top-level urls.py) is to configure the applications for a
particular deployment, so things like STATIC_URL that are specific to a
particular deployment of the app should not be in the app itself.

Thus, the top-level settings.py should include stuff that is:

1. General across all applications, or,
2. Used to configure a particular application for a particular deployment.

All that being said, it's no big deal to emulate the urls.py include facility
in settings.py; just include your app-specific settings. You can also have a
'settings.py' (or whatever) file within the application that only that app
imports.

--
-- Christophe Pettus
x...@thebuild.com

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

Offline

#3 Jan. 1, 2011 06:41:59

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

De-coupling settings.py from project


On 31 December 2010 03:50, eblume <blume.er...@gmail.com> wrote:
> In particular, I'm having trouble specifying the static content URL
> and the fixtures directories at a per-application level rather than in
> the project settings.py file.

Can't you implement a static files finder, in the similar way to
template loaders to achieve the same effect?http://docs.djangoproject.com/en/dev/howto/static-files/New in Django 1.3.

> Is there a way to specify settings like STATIC_URL or FIXTURES_DIRS
> per-application rather than per-site? Even better - is there a
> mechanism to use a settings.py file in the application rather than in
> the site?

As Christophe explained, it is possible, but I also agree with
Christophe - you're going to the extreme for very unlikely use cases.
Also keep in mind that every time Django handles a request, it will
import the settings for *every* app, instead of just the app you think
will be used to handle the request. Settings could then clash, making
debugging a pain.

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

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

Offline

  • Root
  • » Django
  • » De-coupling settings.py from project [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support