當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。