django shell 未检测到新模块
django shell not detecting new module
您好,我有一个名为 "celery_tasks" 的 django 应用程序,其目录结构如下:
.
├── apps.py
├── emitter
├── __init__.py
├── kse
├── mongo
我添加了一个名为 kse 的新模块,其中包含两个文件:
├── __init__.py
├── lol.py
kse模块中的__init__.py
包含from .lol import lol
并且 lol.py 文件包含以下内容 class:
class lol:
@staticmethod
def x():
return True
def __init__(self):
pass
问题是我无法通过 django shell:
访问 kse
模块
>>> 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'
但是 mongo 和 emmiter 模块是可以访问的:
>>> 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'>
我已经按照创建 mongo 和发射器模块的方式创建了 kse
模块,但是我无法访问 kse 模块。
我错过了什么吗?谢谢
更新 1
这里要求的是目录的ls -la
:
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
要以您期望的方式导入模块,您应该在 celery_tasks/__init__.py
中导入 kse
您好,我有一个名为 "celery_tasks" 的 django 应用程序,其目录结构如下:
.
├── apps.py
├── emitter
├── __init__.py
├── kse
├── mongo
我添加了一个名为 kse 的新模块,其中包含两个文件:
├── __init__.py
├── lol.py
kse模块中的__init__.py
包含from .lol import lol
并且 lol.py 文件包含以下内容 class:
class lol:
@staticmethod
def x():
return True
def __init__(self):
pass
问题是我无法通过 django shell:
访问kse
模块
>>> 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'
但是 mongo 和 emmiter 模块是可以访问的:
>>> 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'>
我已经按照创建 mongo 和发射器模块的方式创建了 kse
模块,但是我无法访问 kse 模块。
我错过了什么吗?谢谢
更新 1
这里要求的是目录的ls -la
:
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
要以您期望的方式导入模块,您应该在 celery_tasks/__init__.py
kse