本文整理匯總了Python中bottle.redirect方法的典型用法代碼示例。如果您正苦於以下問題:Python bottle.redirect方法的具體用法?Python bottle.redirect怎麽用?Python bottle.redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bottle
的用法示例。
在下文中一共展示了bottle.redirect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: login
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def login():
"""Prompt user to authenticate."""
auth_state = str(uuid.uuid4())
SESSION.auth_state = auth_state
# For this sample, the user selects an account to authenticate. Change
# this value to 'none' for "silent SSO" behavior, and if the user is
# already authenticated they won't need to re-authenticate.
prompt_behavior = 'select_account'
params = urllib.parse.urlencode({'response_type': 'code',
'client_id': config.CLIENT_ID,
'redirect_uri': config.REDIRECT_URI,
'state': auth_state,
'resource': config.RESOURCE,
'prompt': prompt_behavior})
return bottle.redirect(config.AUTHORITY_URL + '/oauth2/authorize?' + params)
示例2: authorized
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def authorized():
"""Handler for the application's Redirect Uri."""
code = bottle.request.query.code
auth_state = bottle.request.query.state
if auth_state != SESSION.auth_state:
raise Exception('state returned to redirect URL does not match!')
auth_context = adal.AuthenticationContext(config.AUTHORITY_URL, api_version=None)
token_response = auth_context.acquire_token_with_authorization_code(
code, config.REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET)
SESSION.headers.update({'Authorization': f"Bearer {token_response['accessToken']}",
'User-Agent': 'adal-sample',
'Accept': 'application/json',
'Content-Type': 'application/json',
'SdkVersion': 'sample-python-adal',
'return-client-request-id': 'true'})
return bottle.redirect('/graphcall')
示例3: redirect_uri_handler
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def redirect_uri_handler(self):
"""Redirect URL handler for AuthCode workflow. Uses the authorization
code received from auth endpoint to call the token endpoint and obtain
an access token.
"""
# Verify that this authorization attempt came from this app, by checking
# the received state against what we sent with our authorization request.
if self.authstate != bottle.request.query.state:
raise ValueError(f"STATE MISMATCH: {self.authstate} sent, "
f"{bottle.request.query.state} received")
self.authstate = '' # clear state to prevent re-use
data = {
'client_id': self.config['client_id'],
'client_secret': self.config['client_secret'],
'grant_type': 'authorization_code',
'code': bottle.request.query.code,
'redirect_uri': self.config['redirect_uri']
}
token_response = requests.post(self.config['token_endpoint'],
data=data)
self.token_save(token_response)
if token_response and token_response.ok:
self.state_manager('save')
return bottle.redirect(self.login_redirect)
示例4: shortcut_delete
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def shortcut_delete():
name = sanitize(request.forms.get('name'))
platform = sanitize(request.forms.get('platform'))
shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
shortcuts = load_shortcuts(platform)
matches = [e for e in shortcuts if e['name'] == name and e['cmd'] == platform]
shortcut = matches[0]
delete_file(CONTENT_DIR, platform, name)
delete_file(BANNER_DIR, platform, name)
shortcuts.remove(shortcut)
yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)
redirect('/platforms/{platform}'.format(platform=platform))
示例5: flathub_install
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def flathub_install(flatpak_id):
platform = "flathub"
application = FLATHUB_HANDLER.get_application(flatpak_id)
if not application:
abort(404, '{} not found in Flathub'.format(flatpak_id))
application.install()
shortcuts = load_shortcuts(platform)
shortcut = {
'name': application.name,
'hidden': False,
'banner': application.get_image(os.path.join(BANNER_DIR, platform)),
'params': application.flatpak_id,
'cmd': "flatpak run",
'tags': ["Flathub"],
}
shortcuts.append(shortcut)
shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)
redirect('/platforms/{platform}/edit/{name}'.format(platform=platform, name=flatpak_id))
示例6: flathub_uninstall
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def flathub_uninstall(flatpak_id):
platform = "flathub"
application = FLATHUB_HANDLER.get_application(flatpak_id)
if not application:
abort(404, '{} not found in Flathub'.format(flatpak_id))
application.uninstall()
shortcuts = load_shortcuts(platform)
for shortcut in shortcuts:
if application.name == shortcut['name']:
shortcuts.remove(shortcut)
break
shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)
redirect('/platforms/{platform}/edit/{name}'.format(platform=platform, name=flatpak_id))
示例7: authenticate_route_handler
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def authenticate_route_handler():
AUTHENTICATOR.kill()
password = request.forms.get('password')
session = request.environ.get('beaker.session')
keep_password = SETTINGS_HANDLER.get_setting('keep_password') or False
stored_hash = SETTINGS_HANDLER.get_setting('password')
if AUTHENTICATOR.matches_password(password) or keep_password and bcrypt.checkpw(password.encode('utf-8'), stored_hash.encode('utf-8')):
session['User-Agent'] = request.headers.get('User-Agent')
session['Logged-In'] = True
session.save()
redirect('/')
else:
if session.get('Logged-In', True):
session['Logged-In'] = False
session.save()
if not keep_password:
AUTHENTICATOR.reset_password()
AUTHENTICATOR.launch()
return template('login', keep_password=keep_password, failed=True)
示例8: logout
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def logout(self, success_redirect='/login', fail_redirect='/login'):
"""Log the user out, remove cookie
:param success_redirect: redirect the user after logging out
:type success_redirect: str.
:param fail_redirect: redirect the user if it is not logged in
:type fail_redirect: str.
"""
try:
session = self._beaker_session
session.delete()
except Exception as e:
log.debug("Exception %s while logging out." % repr(e))
self._redirect(fail_redirect)
self._redirect(success_redirect)
示例9: make_auth_decorator
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def make_auth_decorator(self, username=None, role=None, fixed_role=False, fail_redirect='/login'):
'''
Create a decorator to be used for authentication and authorization
:param username: A resource can be protected for a specific user
:param role: Minimum role level required for authorization
:param fixed_role: Only this role gets authorized
:param fail_redirect: The URL to redirect to if a login is required.
'''
session_manager = self
def auth_require(username=username, role=role, fixed_role=fixed_role,
fail_redirect=fail_redirect):
def decorator(func):
import functools
@functools.wraps(func)
def wrapper(*a, **ka):
session_manager.require(username=username, role=role, fixed_role=fixed_role,
fail_redirect=fail_redirect)
return func(*a, **ka)
return wrapper
return decorator
return(auth_require)
## Private methods
示例10: generate_robots
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def generate_robots(host):
if host.startswith('robotsdenyall'):
return 'User-Agent: *\nDisallow: /\n'
if host.startswith('404'):
abort(404, 'No robots.txt here')
if host.startswith('500'):
abort(500, 'I don\'t know what I\'m doing!')
if host.startswith('302loop'):
redirect('http://127.0.0.1:8080/robots.txt.302loop') # infinite loop
if host.startswith('302'):
# unfortunately, we can't use a fake hostname here.
# XXX figure out how to get this constant out of here... header?
redirect('http://127.0.0.1:8080/robots.txt.302')
if host.startswith('pdfrobots'):
return '%PDF-1.3\n'
return 'User-Agent: *\nDisallow: /denied/\n'
示例11: file
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def file():
print('[bottle] url: /upload')
print('[bottle] query:', request.query.keys())
print('[bottle] forms:', request.forms.keys())
print('[bottle] files:', request.files.keys())
files = request.files.getall('file')
print('[bottle] files:', files)
save_path = "./save_file"
if not os.path.exists(save_path):
os.mkdir(save_path)
File(files).start()
print('[bottle] redirect: /')
redirect('/')
# print('after redirect') # never executed
示例12: editar
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def editar(slug):
"""Edita un slug"""
if not 'REMOTE_USER' in bottle.request.environ:
bottle.abort(401, "Sorry, access denied.")
usuario = bottle.request.environ['REMOTE_USER'].decode('utf8')
# Solo el dueño de un atajo puede editarlo
a = Atajo.get(slug)
# Atajo no existe o no sos el dueño
if not a or a.user != usuario:
bottle.abort(404, 'El atajo no existe')
if 'url' in bottle.request.GET:
# El usuario mandó el form
a.url = bottle.request.GET['url'].decode('utf-8')
a.activo = 'activo' in bottle.request.GET
a.test = bottle.request.GET['test'].decode('utf-8')
a.save()
bottle.redirect('/')
return {'atajo':a,
'mensaje':'',
}
示例13: server_index
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def server_index():
"""Needed to redirect / to index.html"""
return redirect('index.html')
示例14: server_doc_index
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def server_doc_index():
"""Needed to redirect / to index.html"""
return redirect('doc/index.html')
示例15: server_doc_subindex
# 需要導入模塊: import bottle [as 別名]
# 或者: from bottle import redirect [as 別名]
def server_doc_subindex(subdir):
"""Needed to redirect / to index.html"""
return redirect('%s/index.html' % subdir)