Hackish Way to Execute on manage.py Action

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
from django.core.management import execute_manager
import sys

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)

if __name__ == "__main__":
   
    try:
        action = sys.argv [ sys.argv.index('manage.py')+1 ]
    except:
        action = sys.argv [ sys.argv.index('./manage.py')+1 ]
   
    if action == 'syncdb':
        pass
       
    execute_manager(settings)

More like this

  1. sqlallall.py by jkl 4 years, 6 months ago
  2. reset_db management command by dnordberg 3 years, 7 months ago
  3. Link Media Command by elwaywitvac 3 years, 4 months ago
  4. backupdb command by msaelices 3 years, 7 months ago
  5. Improved command to generate UML diagrams of whole project or specified apps by nikolajusk 1 year, 4 months ago

Comments

(Forgotten your password?)