#20109: django-admin.py does not correctly set DJANGO_SETTINGS_MODULE (patch
attached)
-------------------------------------+-------------------------------------
     Reporter:  jamercee             |      Owner:  nobody
         Type:  New feature          |     Status:  new
    Component:  Core (Management     |    Version:  1.5
  commands)                          |   Keywords:  djang-admin.py,
     Severity:  Normal               |  manage.py, "DJANGO_SETTINGS_MODULE"
 Triage Stage:  Unreviewed           |  Has patch:  1
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 The default '''manage.py''' script (created by '''django-admin.py
 startproject''') does not "correctly" set DJANGO_SETTINGS_MODULE in a way
 that permits running manage.py from another directory.

 We discovered this while working on a custom manage.py command
 (https://docs.djangoproject.com/en/dev/howto/custom-management-commands).
 When trying to run our new command from a directory that was not within
 our project folder, the command extensions were not available. Our
 extensions were only visible when the manage.py command is run from
 withing our project folder.

 The quick fix was to add our project path to sys.path.

 But a better solution is to add this to the
 django/conf/project_template/manage.py template file. Something such as
 this:



 {{{
 diff --git a/django/conf/project_template/manage.py
 b/django/conf/project_template/manage.py
 index 391dd88..656deaf 100755
 --- a/django/conf/project_template/manage.py
 +++ b/django/conf/project_template/manage.py
 @@ -1,8 +1,15 @@
  #!/usr/bin/env python
 +import inspect
  import os
  import sys

  if __name__ == "__main__":
 +    __script__ = inspect.getfile(inspect.currentframe())
 +    __script__ = os.path.realpath(os.path.abspath(__script__))
 +    __dname__  = os.path.dirname(os.path.dirname(__script__))
 +    if __dname__ not in sys.path:
 +        sys.path.insert(0, __dname__)
 +
      os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name
 }}.settings")

      from django.core.management import execute_from_command_line

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20109>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to