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.
当我尝试测试无法访问g变量的烧瓶应用程序时遇到问题。
g
将要测试的 api 如下所示:
user = query_object.get(g.user_id) # here the exception raises
当我运行测试时,它会引发:
NameError: global name 'g' is not defined
你的进口是什么?您应该尝试添加
from flask import g
或者,如果您使用的是 Quart
from quart import g