本文整理匯總了Python中flask.request.args方法的典型用法代碼示例。如果您正苦於以下問題:Python request.args方法的具體用法?Python request.args怎麽用?Python request.args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask.request
的用法示例。
在下文中一共展示了request.args方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: requires_token
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def requires_token(self, audiences=None, allowed_roles=None):
"""
Decorator for functions that will be protected with token authentication.
Token must be provvided either through access_token parameter or Authorization
header.
See check_token() method for further details.
"""
def requires_token_wrapper(f):
@wraps(f)
def decorated(*args, **kwargs):
try:
token = request.args['access_token']
except KeyError:
token = request.headers.get('Authorization', '').partition(' ')[2]
if not self._perform_verification(token, audiences, allowed_roles):
abort(401)
return f(*args, **kwargs)
return decorated
return requires_token_wrapper
示例2: related
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def related():
"""Get related documents or entities."""
if request.args['type'] == 'document':
service = 'related_documents'
elif request.args['type'] == 'entity':
service = 'related_entities'
else:
return Response('Invalid type %s' % request.args['type'])
if not _globals['gransk'].pipeline.get_service(service):
return Response('{"error": "service not found"}', status=200, mimetype='application/json')
result = _globals['gransk'].pipeline.get_service(service).get_related_to(
request.args['id'])
return Response(json.dumps(result), status=200, mimetype='application/json')
示例3: query
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def query(user, repo, query_name, subdir=None, spec_url=None, sha=None, content=None):
"""Execute SPARQL query for a specific grlc-generated API endpoint"""
glogger.info("-----> Executing call name at /{}/{}/{}/{} on commit {}".format(user, repo, subdir, query_name, sha))
glogger.debug("Request accept header: " + request.headers["Accept"])
requestArgs = request.args
acceptHeader = request.headers['Accept']
requestUrl = request.url
formData = request.form
query_response, status, headers = utils.dispatch_query(user, repo, query_name, subdir, spec_url,
sha=sha, content=content, requestArgs=requestArgs,
acceptHeader=acceptHeader,
requestUrl=requestUrl, formData=formData)
if isinstance(query_response, list):
query_response = jsonify(query_response)
return make_response(query_response, status, headers)
### Server routes ###
示例4: google_login
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def google_login():
# to avoid flask-login displaying the login error message
session.pop("_flashes", None)
next_url = request.args.get("next")
# Google does not allow to append param to redirect_url
# we need to pass the next url by session
if next_url:
session["google_next_url"] = next_url
google = OAuth2Session(GOOGLE_CLIENT_ID, scope=_scope, redirect_uri=_redirect_uri)
authorization_url, state = google.authorization_url(_authorization_base_url)
# State is used to prevent CSRF, keep this for later.
session["oauth_state"] = state
return redirect(authorization_url)
示例5: facebook_login
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def facebook_login():
# to avoid flask-login displaying the login error message
session.pop("_flashes", None)
next_url = request.args.get("next")
# Facebook does not allow to append param to redirect_uri
# we need to pass the next url by session
if next_url:
session["facebook_next_url"] = next_url
facebook = OAuth2Session(
FACEBOOK_CLIENT_ID, scope=_scope, redirect_uri=_redirect_uri
)
facebook = facebook_compliance_fix(facebook)
authorization_url, state = facebook.authorization_url(_authorization_base_url)
# State is used to prevent CSRF, keep this for later.
session["oauth_state"] = state
return redirect(authorization_url)
示例6: setup
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def setup(args, pipeline, runmod, injector):
"""Load configuration"""
logging.basicConfig(
format='[%(asctime)s] [%(levelname)s] %(name)s: %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
_globals['gransk'] = gransk.api.API(injector)
_globals['config'] = _globals['gransk'].config
if pipeline:
_globals['gransk'].pipeline = pipeline
if _globals['gransk'].pipeline.get_service('related_entities'):
_globals['gransk'].pipeline.get_service('related_entities').load_all(_globals['config'])
if _globals['gransk'].pipeline.get_service('related_documents'):
_globals['gransk'].pipeline.get_service('related_documents').load_all(_globals['config'])
示例7: listRemove
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def listRemove(self):
cpe = request.args.get('cpe', type=str)
cpe = urllib.parse.quote_plus(cpe).lower()
cpe = cpe.replace("%3a", ":")
cpe = cpe.replace("%2f", "/")
lst = request.args.get('list', type=str)
if cpe and lst:
result=wl.removeWhitelist(cpe) if lst.lower()=="whitelist" else bl.removeBlacklist(cpe)
status = "removed_from_list" if (result > 0) else "already_removed_from_list"
else:
status = "invalid_cpe"
returnList = db.getWhitelist() if lst=="whitelist" else db.getBlacklist()
return jsonify({"status":status, "rules":returnList, "listType":lst.title()})
# /admin/editInList
示例8: listEdit
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def listEdit(self):
old = request.args.get('oldCPE')
new = request.args.get('cpe')
lst = request.args.get('list')
CPEType = request.args.get('type')
if old and new:
result = wl.updateWhitelist(old, new, CPEType) if lst=="whitelist" else bl.updateBlacklist(old, new, CPEType)
status = "cpelist_updated" if (result) else "cpelist_update_failed"
else:
status = "invalid_cpe"
returnList = list(db.getWhitelist()) if lst=="whitelist" else list(db.getBlacklist())
return jsonify({"rules":returnList, "status":status, "listType":lst})
# /admin/listmanagement/<vendor>/<product>
# /admin/listmanagement/<vendor>
# /admin/listmanagement
示例9: matchups
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def matchups() -> str:
hero, enemy = {}, {}
for k, v in request.args.items():
if k.startswith('hero_'):
k = k.replace('hero_', '')
hero[k] = v
else:
k = k.replace('enemy_', '')
enemy[k] = v
season_id = request.args.get('season_id')
results = mus.matchup(hero, enemy, season_id=season_id) if 'hero_person_id' in request.args else {}
matchup_archetypes = archs.load_archetypes_deckless()
matchup_archetypes.sort(key=lambda a: a.name)
matchup_people = list(ps.load_people(where='p.mtgo_username IS NOT NULL'))
matchup_people.sort(key=lambda p: p.name)
matchup_cards = cs.load_cards()
matchup_cards.sort(key=lambda c: c.name)
view = Matchups(hero, enemy, season_id, matchup_archetypes, matchup_people, matchup_cards, results)
return view.page()
示例10: refresh_dag
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def refresh_dag(self, base_response):
logging.info("Executing custom 'refresh_dag' function")
dag_id = request.args.get('dag_id')
logging.info("dag_id to refresh: '" + str(dag_id) + "'")
if self.is_arg_not_provided(dag_id):
return REST_API_Response_Util.get_400_error_response(base_response, "dag_id should be provided")
elif " " in dag_id:
return REST_API_Response_Util.get_400_error_response(base_response, "dag_id contains spaces and is therefore an illegal argument")
try:
from airflow.www.views import Airflow
# NOTE: The request argument 'dag_id' is required for the refresh() function to get the dag_id
refresh_result = Airflow().refresh()
logging.info("Refresh Result: " + str(refresh_result))
except Exception as e:
error_message = "An error occurred while trying to Refresh the DAG '" + str(dag_id) + "': " + str(e)
logging.error(error_message)
return REST_API_Response_Util.get_500_error_response(base_response, error_message)
return REST_API_Response_Util.get_200_response(base_response=base_response, output="DAG [{}] is now fresh as a daisy".format(dag_id))
# Custom Function for the refresh_all_dags API
# This will call the direct function corresponding to the web endpoint '/admin/airflow/refresh_all' that already exists in Airflow
示例11: github_authorize_callback
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def github_authorize_callback():
developer = get_developer()
if developer is None:
return redirect(url_for('main.login'))
resp = github.authorized_response()
if resp is None:
return 'Access denied: reason=%s error=%s' % (
request.args['error_reason'],
request.args['error_description']
)
session['github_token'] = (resp['access_token'], '')
me = github.get('user')
user = me.data['login']
session['user'] = user
authorization = Authorization(developer=developer, oauth_token=session['github_token'][0], type='github')
try:
db.session.add(authorization)
db.session.commit()
return redirect(url_for('auth.github_integration'))
except:
db.session.rollback()
abort(500)
示例12: get_advice
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def get_advice():
args = request.args
answers = []
for k, v in args.items():
answers.append(Answer(int(k), list(map(int, v.split(',')))))
return generate_success_response(course_service.get_advice_result(AnswerSheet(answers)))
示例13: register_by_password_status
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def register_by_password_status():
"""AJAX 刷新教務驗證狀態"""
if not request.args.get("request", None) or not isinstance(request.args["request"], str):
return "Invalid request"
try:
success, message, identifier = user_service.register_by_password_status_refresh(request.args.get("request"))
if success:
# write login state to session
flash(MSG_REGISTER_SUCCESS)
if SESSION_PWD_VER_REQ_ID in session:
del session[SESSION_PWD_VER_REQ_ID]
_set_current_user(identifier) # potential uncaught error
return jsonify({"message": "SUCCESS"})
elif message in ("PASSWORD_WRONG", "INTERNAL_ERROR", "INVALID_REQUEST_ID"):
return jsonify({"message": message})
else:
return jsonify({"message": "NEXT_TIME"})
except everyclass.server.user.exceptions.IdentityVerifyRequestNotFoundError:
return "Invalid request"
except user_service.IdentityVerifyMethodNotExpectedError:
return "Invalid request"
except everyclass.server.user.exceptions.AlreadyRegisteredError:
# 已經注冊成功,但不知為何(可能是網絡原因)進入了中間狀態,沒有執行下麵的刪除 session 的代碼,並且用戶刷新頁麵
if SESSION_PWD_VER_REQ_ID in session:
del session[SESSION_PWD_VER_REQ_ID]
flash(MSG_ALREADY_REGISTERED)
return redirect(url_for('user.login'))
示例14: rootfind
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def rootfind(a, b, args, funciso_here):
solutioniso = 0
try:
solutioniso = brentq(
funciso_here, 0.01, 0.49, args=args
) # works for most cases
except ValueError: # starting values a,b for cases where 0.01/0.49 are not sign changing
try:
solutioniso = brentq(funciso_here, a, b, args=args)
except ValueError:
solutioniso = None # if no solution can be found
return solutioniso
示例15: response_text_basic_rewrite
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import args [as 別名]
def response_text_basic_rewrite(*args, **kwargs): # coverage: exclude
"""本函數在v0.28.3被移除, 對本函數的調用會被映射出去
如果需要查看本函數代碼, 請查看git曆史到 v0.28.3 以前
"""
from warnings import warn
warn("This function is deprecated since v0.28.3, use response_text_basic_mirrorlization() instead", DeprecationWarning)
return response_text_basic_mirrorlization(*args, **kwargs)