gpt4 book ai didi

Django命令抛出TypeError : handle() got an unexpected keyword argument

转载 作者:行者123 更新时间:2023-12-04 16:42:34 27 4
gpt4 key购买 nike

我正在使用Django 1.10.4和Python 3.52。当我尝试通过python manage.py my_command运行Django命令时,出现以下错误:

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "path_to_envs/envs/env_name/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "path_to_envs/envs/env_name/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "path_to_envs/envs/env_name/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "path_to_envs/envs/env_name/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
TypeError: handle() got an unexpected keyword argument 'verbosity'

我可以运行本地django服务器并与管理页面进行交互。包含该命令的应用程序位于我的 settings.py文件中。

以下是django命令的内容:
from django.core.management import BaseCommand
from my_module import MyClass


class Command(BaseCommand):
def handle(self):
my_class = MyClass()
my_class.my_method()

在发生错误时, options字典包含 {'verbosity': 1, 'no_color': False, 'settings': None, 'pythonpath': None, 'traceback': False}。根据字典 no_colortraceback和其他字典的随机顺序,它们将抛出相同的 TypeError。经过一天的搜索,我仍然无法弄清楚问题出在哪里。有没有人见过这个?

最佳答案

经过大量谷歌搜索并拔掉头发后,问题出在handle()的参数个数不正确。

这:

    def handle(self):

应该:
    def handle(self, *args, **options):

关于Django命令抛出TypeError : handle() got an unexpected keyword argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41401202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com