Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Management Command ImportError

I have problem with imported module into my qsl/management/commands/<customcommand>.py file. in fact, my app structure is :

qsl/management/commands/ : dir for my management commands
qsl/management/jobs/ : dir for my mangement jobs

jobs are python classes that contains the job i want to be done in the coresponding command

e.g:

news command in qsl/management/commands/ imports news job in qsl/management/jobs/

my error when i want to execute python manage.py news is an importerror : no module named management.jobs.news

like image 297
k.elkourchi Avatar asked Dec 27 '22 07:12

k.elkourchi


1 Answers

Make sure that all the folders have a __init__.py in them so that they can be imported as modules. The structure is described here: https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

Something like this for your structure:

qsl/
    __init__.py
    models.py
    management/
        __init__.py
        commands/
            __init__.py
            news.py
    jobs/
        __init__.py
        news.py
    tests.py
    views.py
like image 117
Sævar Avatar answered Dec 31 '22 13:12

Sævar