On Sun, 2006-08-06 at 11:02 +0800, limodou wrote:
[...]
> I'v tried the new setup_environ function, and the code is:
>
> import settings
> from django.core.management import setup_environ
> setup_environ(settings)
>
> You can not leave the parameters of setup_environ blank.
Oh, true. This is designed for scripts that run exactly like manage.py:
you import the settings and then call setup the environment and then do
your stuff.
> And you need
> import the settings manually. But I need to know which settings file
> is using. How can I just do like manage.py does:
>
> 1) receive from command line options --settings=
> 2) receive from system environment DJANGO_SETTING_MODULE
> 3) if there is a settings.py in current directory, using it.
Except that isn't quite what manage.py does. Remember that manage.py is
designed to be run from within your project directory and run in the
environment of that particular project. Not to be the ultimately
configurable "run any project" script that django-admin.py is.
What manage.py does do is the following:
- requires you to have a "settings" module in the current path.
If "import settings" doesn't work, it won't run. You can
subsequently override that with --settings=..., but that is only
accidental.
- it forces DJANGO_SETTINGS_MODULE to be the settings module
that it imported in the previous step. This unconditionally (and
intentionally) overrides whatever your environment variable
currently is, since the environment should be correct for the
project it is being run inside of, not for whatever your
external existing environ was.
You sound like you are wanting the full configurability of
django-admin.py, which is quite different. In that case, do what
django-admin.py does: call management.execute_from_command_line(...) but
pass in your own action_mapping dictionary. Alternatively, do whatever
processing you like by setting up an optparse.OptionParser instance and
processing the config variables along with the rest of the config
variables to your script.
This sort of stuff can be worked out by reading the code of
django-admin.py and friends pretty easily. It's not that long or
complicated.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---