Python flask.redirect() Examples
The following are 30
code examples of flask.redirect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask
, or try the search function
.
Example #1
Source File: routes.py From thewarden with MIT License | 8 votes |
def reset_token(token): if current_user.is_authenticated: return redirect(url_for("main.home")) user = User.verify_reset_token(token) if user is None: flash("That is an invalid or expired token", "warning") return redirect(url_for("users.reset_request")) form = ResetPasswordForm() if form.validate_on_submit(): hash = generate_password_hash(form.password.data) user.password = hash db.session.commit() flash("Your password has been updated! You are now able to log in", "success") return redirect(url_for("users.login")) return render_template("reset_token.html", title="Reset Password", form=form)
Example #2
Source File: routes.py From thewarden with MIT License | 7 votes |
def portfolio_main(): transactions = Trades.query.filter_by(user_id=current_user.username) if transactions.count() == 0: return redirect(url_for("main.get_started")) # For now pass only static positions, will update prices and other # data through javascript after loaded. This improves load time # and refresh speed. # Get positions and prepare df for delivery df = positions() df.set_index('trade_asset_ticker', inplace=True) df = df[df['is_currency'] == 0].sort_index(ascending=True) df = df.to_dict(orient='index') if df is None: return redirect(url_for("main.get_started")) return render_template("portfolio.html", title="Portfolio Dashboard", portfolio_data=df)
Example #3
Source File: app.py From oabot with MIT License | 7 votes |
def get_random_edit(): # Check first that we are logged in access_token =flask.session.get('access_token', None) if not access_token: return flask.redirect(flask.url_for('login', next_url=flask.url_for('get_random_edit'))) # Then, redirect to a random cached edit for page_name in list_cache_contents(): # Randomly skip or pick the current one, about 1 % chance. if random() > 0.01: continue cache_fname = "cache/"+to_cache_name(page_name) with open(cache_fname, 'r') as f: page_json = json.load(f) proposed_edits = page_json.get('proposed_edits', []) proposed_edits = [template_edit for template_edit in proposed_edits if (template_edit['classification'] != 'rejected')] if proposed_edits: edit_idx = randint(0, len(proposed_edits)-1) orig_hash = proposed_edits[edit_idx]['orig_hash'] return flask.redirect( flask.url_for('review_one_edit', name=page_name, edit=orig_hash)) return flask.redirect(flask.url_for('index'))
Example #4
Source File: routes.py From thewarden with MIT License | 7 votes |
def login(): if current_user.is_authenticated: return redirect(url_for("main.home")) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) # The get method below is actually very helpful # it returns None if empty. Better than using [] for a dictionary. next_page = request.args.get("next") # get the original page if next_page: return redirect(next_page) else: return redirect(url_for("main.home")) else: flash("Login failed. Please check e-mail and password", "danger") return render_template("login.html", title="Login", form=form)
Example #5
Source File: views.py From circleci-demo-python-flask with MIT License | 6 votes |
def password_reset_request(): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'auth/email/reset_password', user=user, token=token, next=request.args.get('next')) flash('An email with instructions to reset your password has been ' 'sent to you.') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form)
Example #6
Source File: app.py From oabot with MIT License | 6 votes |
def login(): """Initiate an OAuth login. Call the MediaWiki server to get request secrets and then redirect the user to the MediaWiki server to sign the request. """ consumer_token = mwoauth.ConsumerToken( app.config['CONSUMER_KEY'], app.config['CONSUMER_SECRET']) try: redirect, request_token = mwoauth.initiate( app.config['OAUTH_MWURI'], consumer_token) except Exception: app.logger.exception('mwoauth.initiate failed') return flask.redirect(flask.url_for('index')) else: flask.session['request_token'] = dict(zip( request_token._fields, request_token)) return flask.redirect(redirect)
Example #7
Source File: routes.py From thewarden with MIT License | 6 votes |
def reset_request(): if current_user.is_authenticated: return redirect(url_for("main.home")) form = RequestResetForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() send_reset_email(user) flash( "An email has been sent with instructions to reset your" + " password.", "info", ) return redirect(url_for("users.login")) return render_template("reset_request.html", title="Reset Password", form=form)
Example #8
Source File: custom_func.sample.py From zmirror with MIT License | 6 votes |
def custom_prior_redirect_func(request, parse): """ 用于在 prior_request_redirect 阶段的自定义重定向 若返回一个 flask.Response 对象, 则执行重定向, 直接返回这个 Response 若返回None, 则不进行重定向 不应该修改parse变量 (添加头和cookie除外) 详见 `config_default.py` 中 `Custom Redirection` 部分 :param request: flask request object :type request: Request :param parse: the zmirror parse variable :type parse: ZmirrorThreadLocal :rtype: Union[Response, None] """ print(request.url, parse.remote_url) from flask import redirect # 如果你想重定向, 请使用这句 # return redirect("/location/you/want/redirect/to") return None # 不进行自定义重定向
Example #9
Source File: unicorn_binance_websocket_api_manager.py From unicorn-binance-websocket-api with MIT License | 6 votes |
def _start_monitoring_api_thread(self, host, port, warn_on_update): """ Threaded method that servces the monitoring api :param host: IP or hostname to use :type host: str :param port: Port to use :type port: int :param warn_on_update: Should the monitoring system report available updates? :type warn_on_update: bool """ logging.info("Starting monitoring API service ...") app = Flask(__name__) @app.route('/') @app.route('/status/') def redirect_to_wiki(): logging.debug("Visit https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/wiki/UNICORN-" "Monitoring-API-Service for further information!") return redirect("https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/wiki/" "UNICORN-Monitoring-API-Service", code=302) api = Api(app) api.add_resource(BinanceWebSocketApiRestServer, "/status/<string:statusformat>/", "/status/<string:statusformat>/<string:checkcommandversion>", resource_class_kwargs={'handler_binance_websocket_api_manager': self, 'warn_on_update': warn_on_update}) try: dispatcher = wsgi.PathInfoDispatcher({'/': app}) self.monitoring_api_server = wsgi.WSGIServer((host, port), dispatcher) self.monitoring_api_server.start() except RuntimeError as error_msg: logging.critical("Monitoring API service is going down! - Info: " + str(error_msg)) except OSError as error_msg: logging.critical("Monitoring API service is going down! - Info: " + str(error_msg))
Example #10
Source File: routes.py From thewarden with MIT License | 6 votes |
def delete_baccount(id): # type = account or address account = None type = request.args.get("type") if type == "account": account = AccountInfo.query.filter_by( user_id=current_user.username).filter_by(account_id=id) if type == "address": account = BitcoinAddresses.query.filter_by( user_id=current_user.username).filter_by(address_id=id) if (account is None) or (account.count() == 0): flash(f"{type.capitalize()} id: {id} not found. Nothing done.", "warning") return redirect(url_for("node.bitcoin_monitor")) if account.first().user_id != current_user.username: abort(403) account.delete() db.session.commit() flash(f"{type.capitalize()} deleted", "danger") return redirect(url_for("node.bitcoin_monitor"))
Example #11
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def resend_confirmation(): token = current_user.generate_confirmation_token() send_email(current_user.email, 'Confirm Your Account', 'auth/email/confirm', user=current_user, token=token) flash('A new confirmation email has been sent to you by email.') return redirect(url_for('main.index'))
Example #12
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def before_request(): if current_user.is_authenticated: current_user.ping() if not current_user.confirmed \ and request.endpoint[:5] != 'auth.' \ and request.endpoint != 'static': return redirect(url_for('auth.unconfirmed'))
Example #13
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def light_level(level): fan.brightness = int(level) flask.flash("Set light level to {}".format(level)) return flask.redirect(flask.url_for("index"))
Example #14
Source File: main.py From hackernewsbot with MIT License | 5 votes |
def comments_redirect(short_id): """Redirect to comments url""" try: story_id = str(shortener.decode(short_id)) except: return abort(400) hn_url = "https://news.ycombinator.com/item?id={}".format(story_id) return redirect(hn_url)
Example #15
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def toggle_light(): fan.light_toggle() flask.flash("Toggling Light") return flask.redirect(flask.url_for("index"))
Example #16
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def light_off(): fan.light_powered_on = False flask.flash("Turning Light Off") return flask.redirect(flask.url_for("index"))
Example #17
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def light_on(): fan.light_powered_on = True flask.flash("Turning light On") return flask.redirect(flask.url_for("index"))
Example #18
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def inc_speed(): fan.inc_speed() flask.flash("Increased Fan Speed") return flask.redirect(flask.url_for("index"))
Example #19
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def set_speed(speed): fan.speed = int(speed) flask.flash("Set fan speed to {}".format(speed)) return flask.redirect(flask.url_for("index"))
Example #20
Source File: flask_app.py From SenseMe with GNU General Public License v3.0 | 5 votes |
def dec_speed(): fan.dec_speed() flask.flash("Decreased Fan Speed") return flask.redirect(flask.url_for("index"))
Example #21
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash('A confirmation email has been sent to you by email.') return redirect(url_for('auth.login')) return render_template('auth/register.html', form=form)
Example #22
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def logout(): logout_user() flash('You have been logged out.') return redirect(url_for('main.index'))
Example #23
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or password.') return render_template('auth/login.html', form=form)
Example #24
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def unconfirmed(): if current_user.is_anonymous or current_user.confirmed: return redirect(url_for('main.index')) return render_template('auth/unconfirmed.html')
Example #25
Source File: views.py From shhh with MIT License | 5 votes |
def created(): """View to see the link for the created secret.""" link, expires_on = request.args.get("link"), request.args.get("expires_on") if not link or not expires_on: return redirect(url_for("create")) return rt("created.html", link=link, expires_on=expires_on)
Example #26
Source File: routes.py From thewarden with MIT License | 5 votes |
def delacc(): if request.method == "GET": id = request.args.get("id") trade = Trades.query.filter_by(id=id) if trade[0].user_id != current_user.username: abort(403) AccountInfo.query.filter_by(account_id=id).delete() db.session.commit() flash("Account deleted", "danger") return redirect(url_for("transactions.tradeaccounts")) else: return redirect(url_for("transactions.tradeaccounts"))
Example #27
Source File: routes.py From thewarden with MIT License | 5 votes |
def logout(): logout_user() return redirect(url_for("main.home"))
Example #28
Source File: routes.py From thewarden with MIT License | 5 votes |
def register(): if current_user.is_authenticated: return redirect(url_for("main.home")) form = RegistrationForm() if form.validate_on_submit(): hash = generate_password_hash(form.password.data) user = User(username=form.username.data, email=form.email.data, password=hash) db.session.add(user) db.session.commit() flash(f"Account created for {form.username.data}.", "success") return redirect(url_for("users.login")) return render_template("register.html", title="Register", form=form)
Example #29
Source File: routes.py From thewarden with MIT License | 5 votes |
def before_request(): # Before any request at main, check if API Keys are set # But only if user is logged in. if current_user.is_authenticated: transactions = Trades.query.filter_by(user_id=current_user.username) if transactions.count() == 0: return redirect(url_for("main.get_started"))
Example #30
Source File: app.py From oabot with MIT License | 5 votes |
def logout(): """Log the user out by clearing their session.""" flask.session.clear() return flask.redirect(flask.url_for('index'))