pythondjangopython-3.xdjango-shell

django shell not detecting new module


Hello I have a django app name "celery_tasks" with the following directory structure:

.
├── apps.py
├── emitter
├── __init__.py
├── kse
├── mongo

I have added a new module name kse which contains two files:

├── __init__.py
├── lol.py

The __init__.py in the kse module contains from .lol import lol

And the lol.py file contains the following class:

class lol:

    @staticmethod
    def x():
        return True

    def __init__(self):
        pass

The issue is that I cannot access the kse module via django shell:

>>> import celery_tasks
>>> celery_tasks.kse
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: module 'celery_tasks' has no attribute 'kse'

However the mongo and emmiter modules are accessible:

>>> celery_tasks.mongo
<module 'celery_tasks.mongo' from '/Users/kheshav/Linux_projects/rockynode.io/App/rockynode/celery_tasks/mongo/__init__.py'>
>>> celery_tasks.emitter
<module 'celery_tasks.emitter' from '/Users/kheshav/Linux_projects/rockynode.io/App/rockynode/celery_tasks/emitter/__init__.py'>

I have created the kse module in the same way i did for the mongo and emitter module but am not being able to access the kse module.

Did i missed something? Thank you

Update 1

As requested here is the ls -la of the directory:

drwxr-xr-x 11 root root  374 Oct 13 19:28 .
drwxr-xr-x 14 root root  476 Oct 12 22:51 ..
-rw-r--r--  1 root root   98 Dec 11  2016 apps.py
drwxr-xr-x  5 root root  170 Oct 12 19:56 emitter
-rw-r--r--  1 root root    0 Oct 13 20:51 __init__.py
drwxr-xr-x  5 root root  170 Oct 13 19:53 kse
drwxr-xr-x  6 root root  204 Oct 12 19:56 mongo
drwxr-xr-x  3 root root  102 Oct 13 20:50 __pycache__
drwxr-xr-x  5 root root  170 Oct 12 22:51 zabbix

Solution

  • To import the module in the way you expect you should import kse inside celery_tasks/__init__.py