I wrote a function like
def cmd_run(host="localhost", port="8000"):
"""Run server at given host port (or localhost 8000)"""
from django.core import management
host_port = '%s:%s' % (host, port)
management.call_command('runserver', host_port)
When I executed it, an Exception was thrown:
Traceback (most recent call last):
File "/home/leona/workspace/bettyskitchen/lib/djangocliutils/bin/djangoctl", line 8, in <module> cli(*sys.argv[1:])
File "/home/leona/workspace/bettyskitchen/lib/djangocliutils/cmds.py", line 119, in __call__
print method(*args) or ""
File "/home/leona/workspace/bettyskitchen/lib/djangocliutils/cmds.py", line 170, in __call__
return self.method(*args, **kw)
File "/home/leona/workspace/bettyskitchen/lib/djangocliutils/djangocmds/basic.py", line 19, in cmd_run
management.call_command('runserver', host_port)
AttributeError: 'module' object has no attribute 'call_command'
How can I fix it?
Well, here it works… maybe your version of django has not this function? Try it in managed shell
python manage.py shelland tryhelp(management)to see if it is there on your version.Another possibility is corruption or modification of the
__init__.pyfile (where call_command is defined) indjango.core.managementdirectory not importing thecall_commandfunction.