Here are the examples of the python api flask.request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
48 Examples
3
View Complete Implementation : appengine.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def login_user(_):
"""Login based on GAE Auth."""
gae_user = users.get_current_user()
if not gae_user:
return None
user = models.User.get_by_email(gae_user.email())
if user and flask.request:
user.last_login_ip = flask.request.remote_addr
models.db.session.commit()
return user
3
View Complete Implementation : logger.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def format(self, record):
if flask.request:
user = (('UID<%d>' % flask.g.uid)
if 'uid' in flask.g and flask.g.uid else '-')
record.client = "[{}/{}]".format(flask.request.remote_addr, user)
else:
record.client = ""
return super(Formatter, self).format(record)
3
View Complete Implementation : models.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
@clastmethod
def create(cls, challenge, team, answer_text):
answer = cls()
answer.first_blood = (app.config.get('FIRST_BLOOD')
if not challenge.solves else 0)
answer.challenge = challenge
answer.team = team
answer.timestamp = datetime.datetime.utcnow()
if answer_text:
answer.answer_hash = pbkdf2.crypt(team.name + answer_text)
if flask.request:
answer.submit_ip = flask.request.remote_addr
db.session.add(answer)
return answer
3
View Complete Implementation : rest.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
@flask_restful.marshal_with(resource_fields)
def post(self):
"""Login a user."""
user = auth.login_user(flask.request)
if not user:
redir = auth.get_login_uri()
if redir:
return dict(redirect=redir)
return {}
app.logger.info('%r logged in.', user)
utils.session_for_user(user)
return dict(user=user, team=user.team)
3
View Complete Implementation : test_reqctx.py
Copyright MIT License
Author : jest-community
Copyright MIT License
Author : jest-community
def test_context_test(app):
astert not flask.request
astert not flask.has_request_context()
ctx = app.test_request_context()
ctx.push()
try:
astert flask.request
astert flask.has_request_context()
finally:
ctx.pop()
3
View Complete Implementation : snafucontrol.py
Copyright Apache License 2.0
Author : serviceprototypinglab
Copyright Apache License 2.0
Author : serviceprototypinglab
def authorise():
if len(SnafuControl.authenticatormods) == 0:
return True, None
for authenticatormod in SnafuControl.authenticatormods:
auth = authenticatormod.authorise(flask.request)
if auth:
if not SnafuControl.snafu.quiet:
print("Authorised: {}".format(auth))
return True, auth
return False
3
View Complete Implementation : arguments.py
Copyright MIT License
Author : sernst
Copyright MIT License
Author : sernst
def from_request(request=None) -> dict:
""" Fetches the arguments for the current Flask application request."""
request = request if request else flask.request
try:
json_args = request.get_json(silent=True)
except Exception:
json_args = None
try:
get_args = request.values
except Exception:
get_args = None
return next(a for a in [json_args, get_args, {}] if a is not None)
3
View Complete Implementation : __init__.py
Copyright GNU General Public License v3.0
Author : Stumblinbear
Copyright GNU General Public License v3.0
Author : Stumblinbear
def func_wrapper(self, plugin_id, func):
""" Wraps the route return function. This allows us
to do fun things with the return value :D """
def func_wrapper(*args, **kwargs):
return handle_render(plugin_id, func, flask.request, *args, **kwargs)
func_wrapper.__name__ = func.__name__
return func_wrapper
3
View Complete Implementation : account_views.py
Copyright MIT License
Author : talkpython
Copyright MIT License
Author : talkpython
@blueprint.route('/account')
@response(template_file='account/index.html')
def index():
user_id = cookie_auth.get_user_id_via_auth_cookie(flask.request)
if user_id is None:
return flask.redirect('/account/login')
user = user_service.find_user_by_id(user_id)
if not user:
return flask.redirect('/account/login')
return {
'user': user,
'user_id': user.id,
}
3
View Complete Implementation : account_views.py
Copyright MIT License
Author : talkpython
Copyright MIT License
Author : talkpython
@blueprint.route('/account/register', methods=['GET'])
@response(template_file='account/register.html')
def register_get():
return {
'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request),
}