After upgrading from django 1.2.7 to 1.5.1 when trying to run celery by using
python manage.py celeryd -v 2 -l INFO --settings=settings
i got an error saying that
django.core.management.execute_manager
is deprecated in django 1.4
my manage.py
#!/usr/bin/env python
from django.core.management import execute_manager
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__":
execute_from_command_line(settings)
I looked at django 1.4 release notes
django-core-management-execute-manager
as it says there i replaced the execute_manager with a execute_from_command_line
and now i started getting this error message when i restart the server
Traceback (most recent call last):
File "C:\my\manage.py", line 12, in <module>
execute_from_command_line(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 452, in execute_from_command_line
utility = ManagementUtility(argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 226, in __init__
self.prog_name = os.path.basename(self.argv[0])
TypeError: 'module' object is not subscriptable
You're passing a wrong argument to the execute_from_command_line
method. You should do something like below:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<package>.<subpackage>.settings") #path to the settings py file
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
OR
#!/usr/bin/env python
import os
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<package>.<subpackage>.settings") #path to the settings py file
from django.core.management import execute_from_command_line
execute_from_command_line() # by default sys.argv argument is taken
Indeed, the argument of execute_from_command_line
is, as its name suggests, a parsed command line where the 1st element is the executable name, and the others are arguments