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

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

  •  
  •   julyclyde ·
    julyclyde · 2013-05-21 11:26:12 +08:00 · 3716 次点击
    这是一个创建于 4236 天前的主题,其中的信息可能已经有所发展或是发生改变。
    看了看文档
    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   ·   实用小工具   ·   5363 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:29 · PVG 15:29 · LAX 23:29 · JFK 02:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.