Flask confusion with app

前端 未结 3 1140
眼角桃花
眼角桃花 2020-12-29 19:26

I am starting a flask project, and in my code I have

from flask import Flask, render_template, abort
app = Flask(__name__)

Now

3条回答
  •  春和景丽
    2020-12-29 19:58

    That's a bit confusing indeed, due to the poor names choice.

    • app = Flask(__name__): here app is a WSGI application, it implements the corresponding interface and also supports whatever Flask has to offer us on top of that.
    • from app import app : imports exactly that app object from the package app.
    • from app import view: For what heck he's importing views there, is a bit of a mystery, I suppose he wants to make sure that the view bindings are executed. (I'd rather do that in run.py). In any case, that's a kind of importing loop between two modules which is at least confusing as well.

提交回复
热议问题