Permalink
Browse files

updated manage.py

  • Loading branch information...
1 parent da6948f commit c05deff94fe54c83f847c5b742b06aa5b23f92a4 @denibertovic denibertovic committed Jun 23, 2013
Showing with 18 additions and 3 deletions.
  1. +18 −3 manage.py
View
21 manage.py
@@ -1,10 +1,25 @@
#!/usr/bin/env python
-import os
+from os import environ, listdir
+from os.path import join, dirname, abspath, exists
import sys
if __name__ == "__main__":
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
- from django.core.management import execute_from_command_line
+ # Try to discover project name and set the default settings module
+ # based on it. If discovery fails, DJANGO_SETTINGS_MODULE environment
+ # variable must be set.
+
+ root = dirname(abspath(__file__))
+ sys.path.append(root)
+ settings_module = None
+ for name in listdir(root):
+ full_name = join(root, name)
+ if exists(join(full_name, 'settings', '__init__.py')):
+ settings_module = name + '.settings'
+ break
+ if settings_module is not None:
+ environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
+
+ from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

0 comments on commit c05deff

Please sign in to comment.