如何从更深的子文件夹导入?

2024-03-29 12:08:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试导入我的app函数,它位于front/app __init__内部,但不知何故from front.app import app它在^{中无法工作

.
├── settings
│   ├── settings.json
├── front
│   ├── app
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   └── views.cpython-36.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── demo.css
│   │   │   ├── data.json
│   │   │   └── js
│   │   │       └── script.js
│   │   ├── templates
│   │   │   └── public
│   │   │       └── index.html
│   │   ├── views.py
│   │   └── views.pyc
│   └── run.py
├── tooler.py
├── __pycache__
│   └── utils.cpython-36.pyc
├── requirements.txt
├── tester.py
├── tree
└── utils.py

run.py

from app import app

if __name__ == "__main__":
    app.run()

init

from flask import Flask

app = Flask(__name__)

from app import views

我期望running the server flask的输出,但实际输出是ModuleNotFoundError: No module named 'app'


Tags: runfrompyimportjsonappsettingsinit