julyclyde
V2EX  ›  Flask

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

  •  
  •   julyclyde ·
    julyclyde · May 21, 2013 · 4518 views
    This topic created in 4804 days ago, the information mentioned may be changed or developed.
    看了看文档
    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 replies    2014-07-14 03:02:35 +08:00
    shajiquan
        1
    shajiquan  
       Jul 14, 2014
    主要是为了让这个 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)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   977 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
    ♥ Do have faith in what you're doing.