Settings in Pythoncode

17 views
Skip to first unread message

Stefano Probst

unread,
Jan 9, 2013, 5:13:27 AM1/9/13
to django...@googlegroups.com
Hi!
I want to access variables in my code like in the docs. I have a code like the following in settings.py:
codec_baseString = "...XYZ:::"
In a other file (common.py):
from django.conf import settings
def num2short(num, baseString = settings.codec_baseString):
    ....
    ....
I get the error "'Settings' object has no attribute 'codec_baseString' ". In the docs stand:

Note that django.conf.settings isn't a module -- it's an object. So importing individual settings is not possible:

Refer this sentence to the example after the sentence or to my plan with my own variable?
Thanks.

Daniel Roseman

unread,
Jan 9, 2013, 5:24:36 AM1/9/13
to django...@googlegroups.com
Your error is probably because the definition is evaluated at import time, when the values from settings.py have not yet been added to the django.conf.settings object. This would work better:

    def num2short(num, base_string=None):
        if base_string is None:
            base_string = settings.codec_base_string

--
DR.

Stefano Probst

unread,
Jan 9, 2013, 5:30:47 AM1/9/13
to django...@googlegroups.com
The answer:
I compare my variable with the other setting-variables. All other variables are uppercases (-> constant). When I write my variable big, it works.
Reply all
Reply to author
Forward
0 new messages