当前位置: 首页>>代码示例>>Python>>正文


Python flask.redirect方法代码示例

本文整理汇总了Python中flask.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python flask.redirect方法的具体用法?Python flask.redirect怎么用?Python flask.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask的用法示例。


在下文中一共展示了flask.redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: custom_prior_redirect_func

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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  # 不进行自定义重定向 
开发者ID:aploium,项目名称:zmirror,代码行数:27,代码来源:custom_func.sample.py

示例2: get_random_edit

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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')) 
开发者ID:dissemin,项目名称:oabot,代码行数:27,代码来源:app.py

示例3: login

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:dissemin,项目名称:oabot,代码行数:21,代码来源:app.py

示例4: stream_url

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
def stream_url():
    url = flask.request.args.get('url')
    r = requests.get(url)
    # If it's just an HTML page served over HTTPS, no problem
    if url.startswith('https://') and ( 'text/html' in r.headers['Content-Type'] ):
        return flask.redirect(flask.url_for('redirect_to_url', url=url))

    response = flask.make_response()
    response.data = r.content
    response.headers['Content-Type'] = r.headers['Content-Type']
    # Preserve filename if possible
    if 'Content-Disposition' in r.headers:
        response.headers['Content-Disposition'] = r.headers['Content-Disposition'].replace("attachment;", "inline;")
    # Work around incorrect application/octet-stream
    if 'zenodo.org' in url:
        response.headers['Content-Type'] = 'application/pdf'
    return response 
开发者ID:dissemin,项目名称:oabot,代码行数:19,代码来源:app.py

示例5: portfolio_main

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:19,代码来源:routes.py

示例6: login

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:21,代码来源:routes.py

示例7: reset_request

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:18,代码来源:routes.py

示例8: reset_token

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:20,代码来源:routes.py

示例9: delete_baccount

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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")) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:24,代码来源:routes.py

示例10: password_reset_request

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:18,代码来源:views.py

示例11: register_choice

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
def register_choice():
    """注册:第二步:选择注册方式"""
    if not session.get(SESSION_USER_REGISTERING, None):  # 步骤异常,跳回第一步
        return redirect(url_for('user.register'))
    return render_template('user/registerChoice.html') 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:7,代码来源:views.py

示例12: register_by_email

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
def register_by_email():
    """注册:第三步:使用邮箱验证注册"""
    if not session.get(SESSION_USER_REGISTERING, None):  # 步骤异常,跳回第一步
        return redirect(url_for('user.register'))

    identifier = session[SESSION_USER_REGISTERING].identifier

    try:
        request_id = user_service.register_by_email(identifier)
    except Exception as e:
        return handle_exception_with_error_page(e)
    else:
        return render_template('user/emailSent.html', request_id=request_id) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:15,代码来源:views.py

示例13: register_by_password_status

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [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')) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:33,代码来源:views.py

示例14: register_by_password_success

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
def register_by_password_success():
    """验证成功后跳转到用户首页"""
    return redirect(url_for("user.main")) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:5,代码来源:views.py

示例15: logout

# 需要导入模块: import flask [as 别名]
# 或者: from flask import redirect [as 别名]
def logout():
    """用户退出登录"""
    del session[SESSION_CURRENT_USER]
    flash("退出登录成功。")
    return redirect(url_for('main.main')) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:7,代码来源:views.py


注:本文中的flask.redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。