本文整理汇总了Python中werkzeug.utils.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python utils.redirect方法的具体用法?Python utils.redirect怎么用?Python utils.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.utils
的用法示例。
在下文中一共展示了utils.redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _authenticate
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def _authenticate(self, client, interactive=True):
if not client.is_registered():
self._register_client(client)
flask.session['destination'] = flask.request.url
flask.session['state'] = rndstr()
flask.session['nonce'] = rndstr()
# Use silent authentication for session refresh
# This will not show login prompt to the user
extra_auth_params = {}
if not interactive:
extra_auth_params['prompt'] = 'none'
login_url = client.authentication_request(flask.session['state'],
flask.session['nonce'],
extra_auth_params)
auth_params = dict(parse_qsl(login_url.split('?')[1]))
flask.session['fragment_encoded_response'] = AuthResponseHandler.expect_fragment_encoded_response(auth_params)
return redirect(login_url)
示例2: _logout
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def _logout(self):
logger.debug('user logout')
try:
session = UserSession(flask.session)
except UninitialisedSession as e:
logger.info('user was already logged out, doing nothing')
return None
id_token_jwt = session.id_token_jwt
client = self.clients[session.current_provider]
session.clear()
if client.provider_end_session_endpoint:
flask.session['end_session_state'] = rndstr()
end_session_request = EndSessionRequest(id_token_hint=id_token_jwt,
post_logout_redirect_uri=self._get_post_logout_redirect_uri(client),
state=flask.session['end_session_state'])
logger.debug('send endsession request: %s', end_session_request.to_json())
return redirect(end_session_request.request(client.provider_end_session_endpoint), 303)
return None
示例3: get_default_redirect
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def get_default_redirect(self, rule, method, values, query_args):
"""A helper that returns the URL to redirect to if it finds one.
This is used for default redirecting only.
:internal:
"""
assert self.map.redirect_defaults
for r in self.map._rules_by_endpoint[rule.endpoint]:
# every rule that comes after this one, including ourself
# has a lower priority for the defaults. We order the ones
# with the highest priority up for building.
if r is rule:
break
if r.provides_defaults_for(rule) and \
r.suitable_for(values, method):
values.update(r.defaults)
domain_part, path = r.build(values)
return self.make_redirect_url(
path, query_args, domain_part=domain_part)
示例4: delete
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def delete(map_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
if not topic_map.owner:
abort(403)
if request.method == "POST":
# Remove map from topic store
topic_store.delete_topic_map(map_identifier, current_user.id)
# Delete the map's directory
topic_map_directory = os.path.join(bp.root_path, RESOURCES_DIRECTORY, str(map_identifier))
if os.path.isdir(topic_map_directory):
shutil.rmtree(topic_map_directory)
flash("Map successfully deleted.", "success")
return redirect(url_for("map.index"))
return render_template("map/delete.html", topic_map=topic_map)
示例5: send_file
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def send_file(self, file_id, content_type, filename, inline=True):
if self.proxy_downloads == ProxyDownloadsMode.local:
return send_file(filename, self.open(file_id), content_type, inline=inline)
try:
bucket, id_ = self._parse_file_id(file_id)
content_disp = 'inline' if inline else 'attachment'
h = Headers()
h.add('Content-Disposition', content_disp, filename=filename)
url = self.client.generate_presigned_url('get_object',
Params={'Bucket': bucket,
'Key': id_,
'ResponseContentDisposition': h.get('Content-Disposition'),
'ResponseContentType': content_type},
ExpiresIn=120)
response = redirect(url)
if self.proxy_downloads == ProxyDownloadsMode.nginx:
# nginx can proxy the request to S3 to avoid exposing the redirect and
# bucket URL to the end user (since it is quite ugly and temporary)
response.headers['X-Accel-Redirect'] = '/.xsf/s3/' + url.replace('://', '/', 1)
return response
except Exception as e:
raise StorageError('Could not send file "{}": {}'.format(file_id, e)), None, sys.exc_info()[2]
示例6: delete_view
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def delete_view(self):
"""
Delete model view. Only POST method is allowed.
Whether the model could be deleted is decided by model
"""
from flask_admin.helpers import get_redirect_target
return_url = get_redirect_target() or self.get_url('.index_view')
form = self.delete_form()
if self.validate_form(form):
# id is InputRequired()
model_id = form.id.data
model = self.get_one(model_id)
if model is not None and not model.can_delete():
flash(gettext('You are not allowed to delete this object'))
return redirect(return_url)
return super(ModelViewWithAccess, self).delete_view()
示例7: make_redirect_url
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def make_redirect_url(self, path_info, query_args=None, domain_part=None):
"""Creates a redirect URL.
:internal:
"""
suffix = ''
if query_args:
suffix = '?' + self.encode_query_args(query_args)
return str('%s://%s/%s%s' % (
self.url_scheme,
self.get_host(domain_part),
posixpath.join(self.script_name[:-1].lstrip('/'),
url_quote(path_info.lstrip('/'), self.map.charset,
safe='/:|+')),
suffix
))
示例8: init_app
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def init_app(self, app):
self._redirect_uri_config = RedirectUriConfig(app.config)
# setup redirect_uri as a flask route
app.add_url_rule('/' + self._redirect_uri_config.endpoint,
self._redirect_uri_config.endpoint,
self._handle_authentication_response,
methods=['GET', 'POST'])
# dynamically add the Flask redirect uri to the client info
self.clients = {
name: PyoidcFacade(configuration, self._redirect_uri_config.full_uri)
for (name, configuration) in self._provider_configurations.items()
}
示例9: _handle_error_response
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def _handle_error_response(self, error_response, should_redirect=False):
if should_redirect:
# if the current request was from the JS page handling fragment encoded responses we need to return
# a URL for the error page to redirect to
flask.session['error'] = error_response
return '/' + self._redirect_uri_endpoint + '?error=1'
return self._show_error_response(error_response)
示例10: get_response
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def get_response(self, environ):
return redirect(self.new_url, self.code)
示例11: match
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def match(self, path):
"""Check if the rule matches a given path. Path is a string in the
form ``"subdomain|/path(method)"`` and is assembled by the map. If
the map is doing host matching the subdomain part will be the host
instead.
If the rule matches a dict with the converted values is returned,
otherwise the return value is `None`.
:internal:
"""
if not self.build_only:
m = self._regex.search(path)
if m is not None:
groups = m.groupdict()
# we have a folder like part of the url without a trailing
# slash and strict slashes enabled. raise an exception that
# tells the map to redirect to the same url but with a
# trailing slash
if self.strict_slashes and not self.is_leaf and \
not groups.pop('__suffix__'):
raise RequestSlash()
# if we are not in strict slashes mode we have to remove
# a __suffix__
elif not self.strict_slashes:
del groups['__suffix__']
result = {}
for name, value in iteritems(groups):
try:
value = self._converters[name].to_python(value)
except ValidationError:
return
result[str(name)] = value
if self.defaults:
result.update(self.defaults)
if self.alias and self.map.redirect_defaults:
raise RequestAliasRedirect(result)
return result
示例12: bind
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def bind(self, server_name, script_name=None, subdomain=None,
url_scheme='http', default_method='GET', path_info=None,
query_args=None):
"""Return a new :class:`MapAdapter` with the details specified to the
call. Note that `script_name` will default to ``'/'`` if not further
specified or `None`. The `server_name` at least is a requirement
because the HTTP RFC requires absolute URLs for redirects and so all
redirect exceptions raised by Werkzeug will contain the full canonical
URL.
If no path_info is passed to :meth:`match` it will use the default path
info passed to bind. While this doesn't really make sense for
manual bind calls, it's useful if you bind a map to a WSGI
environment which already contains the path info.
`subdomain` will default to the `default_subdomain` for this map if
no defined. If there is no `default_subdomain` you cannot use the
subdomain feature.
.. versionadded:: 0.7
`query_args` added
.. versionadded:: 0.8
`query_args` can now also be a string.
"""
server_name = server_name.lower()
if self.host_matching:
if subdomain is not None:
raise RuntimeError('host matching enabled and a '
'subdomain was provided')
elif subdomain is None:
subdomain = self.default_subdomain
if script_name is None:
script_name = '/'
try:
server_name = _encode_idna(server_name)
except UnicodeError:
raise BadHost()
return MapAdapter(self, server_name, script_name, subdomain,
url_scheme, path_info, default_method, query_args)
示例13: make_redirect_url
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def make_redirect_url(self, path_info, query_args=None, domain_part=None):
"""Creates a redirect URL.
:internal:
"""
suffix = ''
if query_args:
suffix = '?' + self.encode_query_args(query_args)
return str('%s://%s/%s%s' % (
self.url_scheme or 'http',
self.get_host(domain_part),
posixpath.join(self.script_name[:-1].lstrip('/'),
path_info.lstrip('/')),
suffix
))
示例14: __call__
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def __call__(self, environ, start_response):
request = Request(environ)
engine_health = "/1.1/functions/_ops/metadatas"
if (
is_prod
and request.path != engine_health
and request.headers.get("X-Forwarded-Proto") != "https"
):
url = "https://{0}{1}".format(request.host, request.full_path)
return redirect(url)(environ, start_response)
return self.origin_app(environ, start_response)
示例15: delete_collaborator
# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import redirect [as 别名]
def delete_collaborator(map_identifier, collaborator_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
if not topic_map.owner:
abort(403)
collaborator = topic_store.get_collaborator(map_identifier, collaborator_identifier)
if collaborator is None:
abort(404)
error = 0
if request.method == "POST":
if error != 0:
flash(
"An error occurred when submitting the form. Please review the warnings and fix accordingly.",
"warning",
)
else:
topic_store.stop_collaboration(map_identifier, collaborator_identifier)
flash("Collaborator successfully removed.", "success")
return redirect(url_for("map.collaborators", map_identifier=topic_map.identifier))
return render_template(
"map/delete_collaborator.html",
error=error,
topic_map=topic_map,
collaborator_identifier=collaborator_identifier,
collaborator=collaborator,
)