django 工程,使用 virtualenv,创建了一个 app
写了一个 utils.py 在 views 引用了 utils, 我在 pycharm 下面做的开发。 本地都 OK,但是放到开发机器上面,在启动环节就出错。
gunicorn mybook.wsgi 运行时候出错 python3 manger runserver 启动时候出错
错误都是一样,很不解
python3 manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fb2b2a27400>
File "/home/admin/work/mybook/.env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/admin/work/mybook/app/urls.py", line 3, in <module>
from scan import views
File "/home/admin/work/mybook/app/views.py", line 5, in <module>
import utils
ModuleNotFoundError: No module named 'utils'
├── README.md
├── mybook
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── requirements.txt
└── app
├── __init__.py
├── admin.py
├── apps.py
├── editor.py
├── models.py
├── serializers.py
├── sheet.py
├── tests.py
├── uploader.py
├── urls.py
├── utils.py
└── views.py
1
beviniy 2019-03-14 16:35:17 +08:00 1
路径错了,改成 import app.utils 试试,django 的 import 最好用基于当前项目的路径,而不是文件之间的相对路径
|
4
beneo OP 原来我 IDE 里面把 app 设置成为了 source
|
5
beviniy 2019-03-14 16:40:05 +08:00
@beneo settings.py 中有个 path 的设置,可以把当前项目的路径加上去
|