本文整理汇总了Python中flask.g.pop方法的典型用法代码示例。如果您正苦于以下问题:Python g.pop方法的具体用法?Python g.pop怎么用?Python g.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.g
的用法示例。
在下文中一共展示了g.pop方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logout_user
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def logout_user():
"""Logs out the current user.
This will also clean up the remember me cookie if it exists.
This sends an ``identity_changed`` signal to note that the current
identity is now the `AnonymousIdentity`
"""
for key in ("identity.name", "identity.auth_type", "fs_paa", "fs_gexp"):
session.pop(key, None)
# Clear csrf token between sessions.
# Ideally this would be handled by Flask-WTF but...
# We don't clear entire session since Flask-Login seems to like having it.
csrf_field_name = find_csrf_field_name()
if csrf_field_name:
session.pop(csrf_field_name, None)
# Flask-WTF 'caches' csrf_token - and only set the session if not already
# in 'g'. Be sure to clear both. This affects at least /confirm
g.pop(csrf_field_name, None)
session["fs_cc"] = "clear"
identity_changed.send(
current_app._get_current_object(), identity=AnonymousIdentity()
)
_logout_user()
示例2: find_redirect
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def find_redirect(key):
"""Returns the URL to redirect to after a user logs in successfully.
:param key: The session or application configuration key to search for
"""
rv = (
get_url(session.pop(key.lower(), None))
or get_url(current_app.config[key.upper()] or None)
or "/"
)
return rv
示例3: test_02_app_local_store
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def test_02_app_local_store(self):
store1 = get_app_local_store()
store1["hello"] = "world"
g.test_flag = True
# We get the same store even if we push another app context for the same app
with self.app.app_context():
store2 = get_app_local_store()
self.assertEqual(store1, store2)
self.assertEqual(store2["hello"], "world")
self.assertNotIn("test_flag", g)
g.test_flag = False
self.assertEquals(g.test_flag, True)
g.pop("test_flag")
# We get a different store if we push a context for another app
new_app = create_app("testing", "")
with new_app.app_context():
store3 = get_app_local_store()
self.assertNotIn("hello", store3)
self.assertNotEqual(store3, store1)
store3["hello"] = "no!"
store4 = get_app_local_store()
store3["something"] = "else"
self.assertEqual(store4["hello"], "no!")
self.assertEqual(store4["something"], "else")
self.assertEqual(store1, store2)
self.assertEqual(store2["hello"], "world")
示例4: close_topic_store
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def close_topic_store(e=None):
topic_store = g.pop("topicstore", None)
if topic_store is not None:
topic_store.close()
示例5: get_ca
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def get_ca() -> CertificateAuthority:
if 'ca' not in g:
try:
ca = db.session.query(CertificateAuthority).filter_by(common_name='COMMANDMENT-CA').one()
except sqlalchemy.orm.exc.NoResultFound:
ca = CertificateAuthority.create()
g.ca = ca
return g.ca
#
# @current_app.teardown_appcontext
# def teardown_ca():
# ca = g.pop('ca', None)
示例6: close_db
# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import pop [as 别名]
def close_db(e=None):
"""If this request connected to the database, close the
connection.
"""
db = g.pop('db', None)
if db is not None:
db.close()