【发布时间】:2017-01-31 17:09:20
【问题描述】:
我正在开发一个 Flask 应用程序并尝试运行我的测试文件,但无法这样做。我目前的应用结构是:
Project
── app
│ ├── __init__.py
│ ├── forms.py
│ ├── model.py
│ ├── models.py
│ ├── static
│ │ ├── css
│ │ ├── fonts
│ │ ├── img
│ │ ├── js
│ │ └── uploads
│ ├── templates
│ │ ├── client
│ │ │ ├── client-base.html
│ │ │ ├── client-inventory.html
│ │ │ ├── client-login.html
│ │ │ ├── client-macros.html
│ │ │ ├── client-main.html
│ │ │ └── client-signup.html
│ │ └── user
│ │ ├── user-base.html
│ │ ├── user-macros.html
│ │ └── user-main.html
│ └── views
│ ├── __init__.py
│ ├── client.py
│ └── user.py
├── config.py
├── run.py
└── tests
└── test_user_model.py
当我尝试在test_user_model.py 中运行from app.models import User 时,它会引发ModuleNotFoundError: No module named 'app'。我尝试过无数种不同的方式编辑导入语句,但在每种情况下它仍然会引发错误(from ..app import models 超出范围,import app 和类似的导入也不起作用。)
【问题讨论】:
-
你从哪个文件夹运行这个?
标签: python python-3.x flask python-import relative-path