Python flask 模块,get_flashed_messages() 实例源码

我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用flask.get_flashed_messages()

项目:dataviva-api    作者:DataViva    | 项目源码 | 文件源码
def api_cache_key(namespace, *args, **kwargs):
    def gen_key(**kwargs):
        path = request.path
        reqstr = ""
        if request.args:
            for k, v in request.args.items():
                reqstr += "&{}={}".format(str(k), str(v))
        key = namespace + ":" + path + reqstr
        cache_key = key.encode('utf-8')

        if get_flashed_messages():
            msgs = "|".join([msg[0] for msg in get_flashed_messages(with_categories=True)])
            cache_key += "/" + msgs

        return cache_key
    return gen_key
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def last_flashed_message():
    """Return last flashed message by flask."""
    messages = get_flashed_messages(with_categories=True)
    if len(messages) > 0:
        return messages[-1]
    else:
        return None
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:tesismometro    作者:joapaspe    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:fame    作者:certsocietegenerale    | 项目源码 | 文件源码
def validation_error(path=None):
    if choose_media_type(acceptable_media_types(request), [html]):
        if path:
            return flask_redirect(path)
        else:
            return flask_redirect(request.referrer)
    else:
        return render_json({'errors': get_flashed_messages()})
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:tellmeabout.coffee    作者:billyfung    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:ledger-dashboard    作者:Ikke    | 项目源码 | 文件源码
def message():
        messages = get_flashed_messages(category_filter=['message'])
        return messages[0] if len(messages) else None
项目:ledger-dashboard    作者:Ikke    | 项目源码 | 文件源码
def error():
        errors = get_flashed_messages(category_filter=['error'])
        return errors[0] if len(errors) else None
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:QA4LOV    作者:gatemezing    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Sudoku-Solver    作者:ayush1997    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Flask-SocketIO    作者:cutedogspark    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:flask-template-project    作者:andreffs18    | 项目源码 | 文件源码
def assert_flashes(self, expected_message, expected_category='message'):
        flashed_messages = get_flashed_messages(with_categories=True)
        for category, message in flashed_messages:
            if category == expected_category:
                self.assertEqual(message, expected_message)
                return
        raise AssertionError("nothing flashed")
项目:compatify    作者:hatooku    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:compatify    作者:hatooku    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:ropi    作者:ThumbGen    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:skojjt    作者:martin-green    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:zoom-autocomplete-demo    作者:kenju254    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:noobotkit    作者:nazroll    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:flask-alcohol    作者:natfoster82    | 项目源码 | 文件源码
def api_messages():
    messages = get_flashed_messages()
    default_message = current_app.config.get('API_ERROR_MESSAGE')
    if default_message:
        messages.append(default_message)
    return messages
项目:subroofer    作者:Sypherio    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:subroofer    作者:Sypherio    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:facebook-face-recognition    作者:mathur    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:Hawkeye    作者:tozhengxq    | 项目源码 | 文件源码
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
项目:anime-birb-uk    作者:Arctice    | 项目源码 | 文件源码
def recommendations(profile=None):
    profile_form = profile_search_form()

    if not profile:
        return render_template(
            'index.html',
            profile_form=profile_form,
            )

    if not valid_mal_username(profile):
        return redirect(url_for('invalid_name', name=profile))

    print(f"received {profile} request")
    profile_form.name.data = profile 

    profile = profile.lower()
    messages = []
    diff, recommendations = latest_recommendations(profile, redis_connection)

    if recommendations == []:
        messages += [Markup('<br>I\'ve got nothing! Please make sure that: <ul><li>you\'ve typed the name of your profile correctly, <li> it <b>isn\'t private</b>, <li>and <b>your lists have scores on them</b>,</ul> then try to make another request.\n<br>')]
    elif recommendations is not None:
        recs_age = time_hreadable(diff)
        messages += [f'Displaying data from [{recs_age}] ago.']

    request_available = False
    time_remaining = None
    queue_pos = total_queue_position(profile, redis_connection)

    if queue_pos:
        messages += [f'Your position in queue: {queue_pos}']
        messages += [Markup('Refresh the page later to see your recommendations - this process can take a while!')]
    elif diff is not None and diff < REFRESH_LIMIT:
        time_remaining = time_hreadable(int(REFRESH_LIMIT-diff))
    else:
        messages += ["You can make a new request now, using the 'update' button on the right."]
        request_available = True

    if recommendations and not get_flashed_messages():
        messages += [f'Tip: score more media on MAL for more accurate suggestions!']

    return render_template(
        'recommendations.html',
        recommendations=recommendations,
        profile=profile,
        messages=messages,
        profile_form=profile_form,
        heavy_load=display_captcha(redis_connection),
        update_request=update_request_form(),
        request_available=request_available,
        time_remaining=time_remaining,
        )