tags:

views:

31

answers:

2
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)

I wrote a command like this. When I execute it. Exception was thrown:

Traceback (most recent call last):

File "/home/leona/workspace/bettyskitchen/lib/djangocliutils/bin/djangoctl", line 8, in 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 to fix it ?

A: 

Well, here it works... maybe your version of django has not this function? Try it in managed shell python manage.py shell and try help(management) to see if it is there on your version. Another possibility is corruption or modification of the __init__.py file (where call_command is defined) in django.core.management directory not importing the call_command function.

laurent-rpnet
A: 

This problem is resolved, the django that I used was 0.96 not support call_command function, so I changed into :

def cmd_run(host="localhost", port="8000"):
    """Run server at given host port (or localhost 8000)"""
    from django.core import management
    management.runserver(host, port)

and this time it works!

leona
I don't know your reasons behind using 0.96, but i suggest upgrading to newer version if possible.
rebus