本文整理匯總了Python中flask.request.referrer方法的典型用法代碼示例。如果您正苦於以下問題:Python request.referrer方法的具體用法?Python request.referrer怎麽用?Python request.referrer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask.request
的用法示例。
在下文中一共展示了request.referrer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: protect
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def protect(self):
if request.method not in self._app.config['WTF_CSRF_METHODS']:
return
if not validate_csrf(self._get_csrf_token()):
reason = 'CSRF token missing or incorrect.'
return self._error_response(reason)
if request.is_secure and self._app.config['WTF_CSRF_SSL_STRICT']:
if not request.referrer:
reason = 'Referrer checking failed - no Referrer.'
return self._error_response(reason)
good_referrer = 'https://%s/' % request.host
if not same_origin(request.referrer, good_referrer):
reason = 'Referrer checking failed - origin does not match.'
return self._error_response(reason)
request.csrf_valid = True # mark this request is csrf valid
示例2: version
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def version():
if is_valid_origin(request.referrer):
response = make_response(jsonify({
"version": PROTOCOL_VERSION
}))
if request.referrer:
response.headers['Access-Control-Allow-Origin'] = \
request.referrer[:-1] if request.referrer.endswith("/") else \
request.referrer[:-1]
response.headers['Content-Type'] = 'application/json'
return response
else:
return answers_with_404()
示例3: default_unauthz_handler
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def default_unauthz_handler(func, params):
unauthz_message, unauthz_message_type = get_message("UNAUTHORIZED")
if _security._want_json(request):
payload = json_error_response(errors=unauthz_message)
return _security._render_json(payload, 403, None, None)
view = config_value("UNAUTHORIZED_VIEW")
if view:
if callable(view):
view = view()
else:
try:
view = get_url(view)
except BuildError:
view = None
do_flash(unauthz_message, unauthz_message_type)
redirect_to = "/"
if request.referrer and not request.referrer.split("?")[0].endswith(
request.path
):
redirect_to = request.referrer
return redirect(view or redirect_to)
abort(403)
示例4: protect
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def protect(self):
if request.method not in current_app.config['WTF_CSRF_METHODS']:
return
try:
validate_csrf(self._get_csrf_token())
except ValidationError as e:
logger.info(e.args[0])
self._error_response(e.args[0])
if request.is_secure and current_app.config['WTF_CSRF_SSL_STRICT']:
if not request.referrer:
self._error_response('The referrer header is missing.')
good_referrer = 'https://{0}/'.format(request.host)
if not same_origin(request.referrer, good_referrer):
self._error_response('The referrer does not match the host.')
g.csrf_valid = True # mark this request as CSRF valid
示例5: _redirect_target_url
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def _redirect_target_url(d, use_referrer, endpoint, **values):
"""
return redirect url to (in that order):
- <next> from d
- referrer (if use_referrer is True)
- the url for endpoint/values
"""
targets = [d.get('next'), request.referrer, url_for(endpoint, **values)]
if not use_referrer:
del targets[1]
for target in targets:
if target and is_safe_url(target):
return target
# GET - for next 2, you may want to create urls with:
# url_for(endpoint, ..., next=something)
示例6: font_files
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def font_files():
if is_valid_origin(request.referrer):
response = make_response(jsonify({
"version": PROTOCOL_VERSION,
"fontFiles": FONT_FILES
}))
if request.referrer:
response.headers['Access-Control-Allow-Origin'] = \
request.referrer[:-1] if request.referrer.endswith("/") else \
request.referrer[:-1]
response.headers['Content-Type'] = 'application/json'
return response
else:
return answers_with_404()
示例7: font_file
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def font_file():
file_name = request.args.get("file")
if file_name:
if file_name in FONT_FILES:
with open(file_name, 'rb') as bites:
response = make_response(send_file(
io.BytesIO(bites.read()),
attachment_filename=os.path.basename(file_name),
mimetype='application/octet-stream'
))
if request.referrer:
response.headers['Access-Control-Allow-Origin'] = \
request.referrer[:-1] if request.referrer.endswith("/") else \
request.referrer[:-1]
response.headers['Content-Type'] = 'application/json'
return response
return ('', 404)
示例8: need_update
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def need_update():
if is_valid_origin(request.referrer):
response = make_response(jsonify({
"version": PROTOCOL_VERSION
}))
if request.referrer:
response.headers['Access-Control-Allow-Origin'] = \
request.referrer[:-1] if request.referrer.endswith("/") else \
request.referrer[:-1]
response.headers['Content-Type'] = 'application/json'
return response
else:
return answers_with_404()
示例9: reset_api
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def reset_api(self, id):
"""Reset a user's API key.
.. :quickref: User; Reset API key
When used on another user account, requires the `manage_users` permission.
:param id: user id.
:>json User user: modified user.
"""
self.ensure_permission(id)
user = User(get_or_404(User.get_collection(), _id=id))
user.update_value('api_key', User.generate_api_key())
return redirect({'user': clean_users(user)}, request.referrer)
示例10: validation_error
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def validation_error(path=None):
if choose_media_type(acceptable_media_types(request), [html]):
if path:
return flask_redirect(path)
else:
return flask_redirect(request.referrer)
else:
return render_json({'errors': get_flashed_messages()})
示例11: add_comment
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def add_comment(self, id):
if comments_enabled():
f = File(get_or_404(current_user.files, _id=id))
if current_user.has_permission('add_probable_name'):
probable_name = request.form.get('probable_name')
else:
probable_name = None
comment = request.form.get('comment')
analysis_id = request.form.get('analysis')
notify = request.form.get('notify')
if comment:
# If there is an analysis ID, make sure it is accessible
if analysis_id:
get_or_404(current_user.analyses, _id=analysis_id)
f.add_comment(current_user['_id'], comment, analysis_id, probable_name, notify)
else:
flash('Comment should not be empty', 'danger')
return redirect(request.referrer)
示例12: permissions
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def permissions(self, id):
user = get_object_or_404(User, id=id)
permdict = {}
if request.method == "POST":
for object_name, permissions in user.permissions.items():
if not isinstance(permissions, dict):
permdict[object_name] = bool(
request.form.get("{}".format(object_name), False))
else:
if object_name not in permdict:
permdict[object_name] = {}
for p in permissions:
permdict[object_name][p] = bool(
request.form.get(
"{}_{}".format(object_name, p), False))
user.permissions = permdict
user.save()
flash("Permissions changed successfully", "success")
return redirect(request.referrer)
return render_template("user/permissions.html", user=user)
示例13: restart_worker
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def restart_worker(self, name="all"):
response = celery_app.control.broadcast(
'pool_restart',
arguments={'reload': True},
destination=[name] if name != "all" else None,
reply=True,
)
nok = []
for r in response:
for name in r:
if 'ok' not in r[name]:
nok.append(name)
if nok:
flash(
"Some workers failed to restart: {}".format(", ".join(nok)),
"danger")
flash(
"Succesfully restarted {} workers".format(len(response)), "success")
return redirect(request.referrer)
示例14: authorize_view
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def authorize_view(self):
"""Flask view that starts the authorization flow.
Starts flow by redirecting the user to the OAuth2 provider.
"""
args = request.args.to_dict()
# Scopes will be passed as mutliple args, and to_dict() will only
# return one. So, we use getlist() to get all of the scopes.
args['scopes'] = request.args.getlist('scopes')
return_url = args.pop('return_url', None)
if return_url is None:
return_url = request.referrer or '/'
flow = self._make_flow(return_url=return_url, **args)
auth_url = flow.step1_get_authorize_url()
return redirect(auth_url)
示例15: variant
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import referrer [as 別名]
def variant(institute_id, case_name, variant_id):
"""Display a specific SNV variant."""
LOG.debug("Variants view requesting data for variant %s", variant_id)
data = variant_controller(store, institute_id, case_name, variant_id=variant_id)
if data is None:
LOG.warning(
"An error occurred: variants view requesting data for variant {}".format(variant_id)
)
flash("An error occurred while retrieving variant object", "danger")
return redirect(request.referrer)
if current_app.config.get("LOQUSDB_SETTINGS"):
LOG.debug("Fetching loqusdb information for %s", variant_id)
data["observations"] = observations(store, loqusdb, data["case"], data["variant"])
return data