我试图从位于django项目目录外的python文件调用函数视图.py. 我尝试导入python文件,但是运行django服务器时显示“没有名为xxxx的模块”。在
树形结构如下所示。在
├── auto_flash │ ├── __init__.py │ └── test.py └── fireflash ├── detection_reports │ ├── admin.py │ ├── admin.pyc │ ├── __init__.py │ ├── __init__.pyc │ ├── migrations │ │ ├── __init__.py │ │ └── __init__.pyc │ ├── models.py │ ├── models.pyc │ ├── __pycache__ │ │ └── __init__.cpython-35.pyc │ ├── templates │ │ └── detection_reports │ │ └── home.html │ ├── tests.py │ ├── views.py │ └── views.pyc ├── fireflash │ ├── __init__.py │ ├── __init__.pyc │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ └── settings.cpython-35.pyc │ ├── settings.py │ ├── settings.pyc │ ├── ui_cgi.py │ ├── urls.py │ ├── urls.pyc │ ├── wsgi.py │ └── wsgi.pyc ├── __init__.py └── manage.py
在这里有一个名为“FireU”的项目名为“项目检测”。还有一个名为“auto_flash”的目录与“fireflash”的位置相同。我想做的是什么测试.py检测中的“自动闪存”文件_报告.视图从视图调用函数。像这样导入“from auto_flash import test”会抛出错误“no module named auto_flash”。在
auto_flash
移到fireflash
detection_reports
中添加from auto_flash import test.py
我已经尝试了上述所有的解决方案,但是更简单的解决方案是将
auto_flash
的路径附加到syspath
上,问题就解决了。感谢你们的努力。在相关问题 更多 >
编程相关推荐