问题描述
我开始一个 flask
项目,并且在我的代码中我有
from flask import Flask,render_template,abort
app = Flask(__ name__)
现在到底什么是 app
?
我正在关注,我对结构特别困惑,因为他选择了一个名为 app /
并且是他的 app / __ init __。py
他有
<$从应用程序导入视图
从烧瓶导入Flask
app = Flask(__ name__)
和他的 app / views.py
他有
<$ p $从应用程序导入应用程序
code> app
's?!
我觉得主要的困惑是line:
file)命名为app。从这个文件夹中,您现在正在导入您在
$ b $你有一个python包(一个包含 __ init __。py__ init __。py
文件中定义的变量app:
app = Flask(__ name__)
说myproject。然后,您将从myproject导入应用程序
中调用
另外,您将从myproject导入视图
导入视图为
pre $
I am starting a flask
project, and in my code I have
from flask import Flask, render_template, abort
app = Flask(__name__)
Now what exactly is app
?
I am following this guide and I am particularly confused about the structure because he has chosen to have directory named app/
and is his app/__init__.py
he has
from flask import Flask
app = Flask(__name__)
from app import views
and in his app/views.py
he has
from app import app
What the hell is it with all these app
's?!
I think the main confusion is in the line:
from app import app
You have a python package (a folder with __init__.py
file) named "app". From this folder, you are now importing the variable "app" that you defined below in __init__.py
file:
app = Flask(__name__)
Rename the folder from app to say "myproject". Then you will call
from myproject import app
Also, you will import views as
from myproject import views
这篇关于烧瓶与应用程序混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!