Python Django管理命令无法返回dict

Python Django管理命令无法返回dict,python,django,Python,Django,我已经编写了一个管理命令: class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument("member_id", nargs="+", type=str) def handle(self, *args, **options): return other_function(options["member_id"][0]) 调用导入函数的: de

我已经编写了一个管理命令:

class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument("member_id", nargs="+", type=str)

    def handle(self, *args, **options):
        return other_function(options["member_id"][0])
调用导入函数的:

def other_function(identifier):
    return {"foo": "bar"}
当我从shell调用另一个函数时,它工作正常;但是,当使用管理命令时,我得到:

  File "/Volumes/www/bin/../apps/manage.py", line 61, in <module>
    execute_from_command_line(sys.argv)
  File "/Volumes/www/src/django/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/Volumes/www/src/django/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Volumes/www/src/django/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Volumes/www/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 41, in new_execute
    return original_func(self, *args, **kwargs)
  File "/Volumes/www/src/django/django/core/management/base.py", line 454, in execute
    self.stdout.write(output)
  File "/Volumes/www/src/django/django/core/management/base.py", line 111, in write
    if ending and not msg.endswith(ending):
AttributeError: 'dict' object has no attribute 'endswith'
文件“/Volumes/www/bin/。/apps/manage.py”,第61行,在
从命令行(sys.argv)执行命令
文件“/Volumes/www/src/django/django/core/management/\uuuuu init\uuuuuu.py”,第354行,从命令行执行
utility.execute()
文件“/Volumes/www/src/django/django/core/management/_init__.py”,第346行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/Volumes/www/src/django/django/core/management/base.py”,第394行,运行于\u argv
self.execute(*args,**cmd_选项)
文件“/Volumes/www/lib/python2.7/site packages/raven/contrib/django/management/_init__.py”,第41行,新文件
返回原始函数(self、*args、**kwargs)
文件“/Volumes/www/src/django/django/core/management/base.py”,执行中的第454行
self.stdout.write(输出)
文件“/Volumes/www/src/django/django/core/management/base.py”,第111行,以书面形式
如果结束而不是消息endswith(结束):
AttributeError:“dict”对象没有属性“endswith”

管理命令只能返回字符串吗?文档中似乎没有这样说,但是如果我将
handle
函数更改为
return“foo”
它就会工作。但这似乎很愚蠢。

是的。如果返回任何内容,它必须返回字符串。“它可能返回将打印到标准输出的Unicode字符串”

文档确实说它必须返回unicode字符串:我看到了,但对“可能”的解释不同。谢谢