V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
julyclyde
V2EX  ›  Flask

Flask(这个参数)是干嘛用的?

  •  
  •   julyclyde ·
    julyclyde · 2013-05-21 11:26:12 +08:00 · 3577 次点击
    这是一个创建于 3993 天前的主题,其中的信息可能已经有所发展或是发生改变。
    看了看文档
    http://flask.pocoo.org/docs/design/#the-explicit-application-object
    Whenever you create a Flask instance you usually pass it __name__ as package name. Flask depends on that information to properly load resources relative to your module.

    http://flask.pocoo.org/docs/api/#application-object
    The name of the package is used to resolve resources from inside the package or the folder the module is contained in depending on if the package parameter resolves to an actual python package (a folder with an __init__.py file inside) or a standard module (just a .py file).

    但没理解啥意思
    1 条回复    2014-07-14 03:02:35 +08:00
    shajiquan
        1
    shajiquan  
       2014-07-14 03:02:35 +08:00
    主要是为了让这个 Flask App 对象保持唯一性。随便创建一个 hehe.py 文件,复制下面的代码进去,然后运行一下:

    print(__name__)

    from flask import Flask

    app = Flask(__name__)
    print(app)
    print(app.name)


    app2 = Flask("shajiquan")
    print(app2)
    print(app.name)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5373 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:14 · PVG 16:14 · LAX 01:14 · JFK 04:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.