﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20109	django-admin.py does not correctly set DJANGO_SETTINGS_MODULE (patch attached)	jamercee	nobody	"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

}}}
"	New feature	closed	Core (Management commands)	1.5	Normal	invalid	"djang-admin.py, manage.py, ""DJANGO_SETTINGS_MODULE"""		Unreviewed	1	0	0	0	0	0
