擅长:python、mysql、java
<p>Python是一种解释语言。当涉及到一行时,它会尝试执行它。这就是为什么在定义app之前不能导入<code>views</code>。你知道吗</p>
<p><code>__init__.py</code>的工作版本</p>
<pre><code>app = Flask(__name__)
from app import views # it will "execute: views.py"
# views.py - indenting for better understanding
from app import app # App is defined here and it can be imported
</code></pre>
<p><code>__init__.py</code>的非工作版本</p>
<pre><code>from app import vies # it will execute vies.py"
# vies.py - indenting for better understanding
from app import app # Exception - app doesn't exist here
app = Flask(__name__)
</code></pre>
<p>您需要非常小心python导入。你知道吗</p>