On 19/09/2013 3:59pm, Victor Hooi wrote:
Hi,

Hmm, in many cases there isn't really a sensible default (e.g. API keys
or passwords).

I was asking more in terms of - is this the "right" way of doing it in
Django, or are people using some other technique to handle configuration
you don't want in the repo?

And is there a special exception type you should throw if it's not being
set, or is there a better way to handle it?

Well worth checking out Two Scoops of Django - it has half a chapter on exactly this topic. In summary, the authors say to use environment variables and to raise ImproperlyConfigured if they don't work.


Cheers,
Victor

On Thursday, 19 September 2013 15:54:15 UTC+10, Dig wrote:

    Hi,

       Do you means some thing like this?

    os.environ.get('SOME_VARIABLE', 'default_value')

    Regards,
    Dig

    On Sep 19, 2013 1:37 PM, "Victor Hooi" <victo...@gmail.com
    <javascript:>> wrote:

        Hi,

        I have several settings in my Django settings.py file that are
        specific

        Currently, I'm grabbing these from environment variables in
        settings.py:

            import os
            ...
            # TODO - We need to gracefully catch if these aren't set.
            SOME_VARIABLE = os.environ['SOME_VARIABLE']


        This includes things like API keys, database IPs, database
        username/passwords, static file locations etc.

        I then set these in the virtualenv activate script.

        Is this a good practice in Django?

        Also, is there a graceful way of catching when these aren't set?
        Currently, I'm using some of those settings variables in
        models.py, and it's failing silently. Should I put each
        os.environ call in a try/except block, or is there a more
        Pythonic way?

        Cheers,
        Victor

        --
        You received this message because you are subscribed to the
        Google Groups "Django users" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to django-users...@googlegroups.com <javascript:>.
        To post to this group, send email to django...@googlegroups.com
        <javascript:>.
        Visit this group at http://groups.google.com/group/django-users
        <http://groups.google.com/group/django-users>.
        For more options, visit https://groups.google.com/groups/opt_out
        <https://groups.google.com/groups/opt_out>.

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to