Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何让 Flask 将我自己的一些上下文与 url 上下文一起传递?我想在通过 add_url_rule 提供 URL 时设置上下文:
app = Flask(__name__) app.add_url_rule('/myproj/one, view_func=myfuncone, methods=['GET'], context=mycontextone)
我想在 Flask 调用myfuncone()时访问mycontextone。
好奇 - 据我所知,它看起来不像烧瓶中的一个选项,但你可以包装你的观点:
def myfuncone(id, **kwargs): print kwargs.keys() import functools myfuncone_with_context = functools.partial(myfuncone, context=mycontextone) app.add_url_rule('/myproj/one', methods=['GET'], view_func=myfuncone_with_context)