Django管理命令ImportError

jok*_*ons 4 python django importerror pythonpath

导入模块到我的qsl/management/commands/<customcommand>.py文件有问题.事实上,我的app结构是:

qsl/management/commands/ : dir for my management commands
qsl/management/jobs/ : dir for my mangement jobs
Run Code Online (Sandbox Code Playgroud)

jobs是python类,包含我想在coresponding命令中完成的工作

例如:

news command in qsl/management/commands/ imports news job in qsl/management/jobs/
Run Code Online (Sandbox Code Playgroud)

我想要执行时的错误python manage.py newsimporterror : no module named management.jobs.news

Sæv*_*var 9

确保所有文件夹都包含__init__.py在其中,以便可以将它们作为模块导入.该结构如下所述:https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

你的结构有这样的东西:

qsl/
    __init__.py
    models.py
    management/
        __init__.py
        commands/
            __init__.py
            news.py
    jobs/
        __init__.py
        news.py
    tests.py
    views.py
Run Code Online (Sandbox Code Playgroud)