#13235: Better manage.py: import django after importing settings
-----------------------------+----------------------------------------------
 Reporter:  rudi             |       Owner:            
   Status:  new              |   Milestone:            
Component:  User Experience  |     Version:  SVN       
 Keywords:  manage settings  |       Stage:  Unreviewed
Has_patch:  1                |  
-----------------------------+----------------------------------------------
 Sometimes it may be necessary to use custom versions of libs for certain
 project. They may be placed to special dir which should be first in
 `sys.path`. This dir may be inserted to `sys.path` at first lines in
 settings.py

 {{{
 #!python
 import os
 import sys
 PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
 PROJECT_LIBS = os.path.realpath(os.path.join(PROJECT_ROOT, '..', 'lib'))
 if not PROJECT_LIBS in sys.path: sys.path.insert(0, PROJECT_LIBS)
 }}}

 But! We can't place custom `django` to that dir, because `manage.py`
 imports `django` first, then imports `settings`. It seems, the more
 preferred way is to import settings first.

 {{{
 #!python
 #!/usr/bin/env python
 try:
     import settings # Assumed to be in the same directory.
 except ImportError:
     import sys
     sys.stderr.write("Error: Can't find the file 'settings.py' in the
 directory containing %r. It appears you've customized things.\nYou'll have
 to run django-admin.py, passing it your settings module.\n(If the file
 settings.py does indeed exist, it's causing an ImportError somehow.)\n" %
 __file__)
     sys.exit(1)

 from django.core.management import execute_manager
 if __name__ == "__main__":
     execute_manager(settings)
 }}}

 The example above is based on original manage.py, but with one line moved
 from top to bottom:
 {{{
 #!python
 from django.core.management import execute_manager
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13235>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en.

Reply via email to