settings.configure() does not allow me to access custom variables in settings.py

37 views
Skip to first unread message

Chen Xu

unread,
Jul 4, 2014, 5:13:55 PM7/4/14
to django...@googlegroups.com
Hi Everyone,
I want to access some variables in my settings.py without starting my server, I know I will have to run settings.configure(); however, running settings.configure() does not allow me to access my custom variables.

What should I do with that.


Thanks

--
⚡ Chen Xu

Mike Dewhirst

unread,
Jul 4, 2014, 8:38:07 PM7/4/14
to django...@googlegroups.com
Perhaps read in the settings file and look for the settings of interest
using plain python. Should not take too long and it would make a useful
little utility. If necessary, hack settings.configure() to use your
utility when it doesn't find a Django setting. Maybe submit the
resulting improvement as a patch?

Mike

>
>
> Thanks
>
> --
> âš¡ Chen Xu âš¡
>
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACac-qbCUJ3WCDVN022%3DU6nnh40X4tYPiW8oJ6q%3DY_LTGN9Bhw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACac-qbCUJ3WCDVN022%3DU6nnh40X4tYPiW8oJ6q%3DY_LTGN9Bhw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Bill Freeman

unread,
Jul 7, 2014, 4:45:58 PM7/7/14
to django-users
I don't know how fussy about not using stuff from django you are, but the following works for me:

  $ DJANGO_SETTINGS_MODULE=foo.ct python
  >>> from django.conf import settings
  >>> settings.INSTALLED_APPS

Obviously, you replace "foo" with the name of your project.  This prints my installed apps.  For settings with defaults, middlewares, for example, you will the default if you haven't set it in your settings file.

You must have DJANGO_SETTINGS_MODULE in the environment, though you could, instead of using the shell, add it to os.environ (I don't think that it has to be there for the import from django.conf, but it must be there for the first reference to an attribute of settings, which is a lazy object).

This doesn't import much, unless you have a things implied in your project path or settings module.  I have the currect celery boiler plate in my project's __init__.py file, so I get a lot of stuff.  Just check sys.modules and see if the import load is too much for you before you go re-implementing the django.conf mechanisms.


--
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.
To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages