python flask web开发实战 页面消息提醒 常用

python flask web开发实战 页面消息提醒 常用_第1张图片
image.png

from flask import Flask, render_template, session, redirect, url_for, flash
@app.route('/', methods=['GET', 'POST'])
def index():
form = NameForm()
if form.validate_on_submit():
old_name = session.get('name')
if old_name is not None and old_name != form.name.data:
flash('Looks like you have changed your name!')
session['name'] = form.name.data
return redirect(url_for('index'))
return render_template('index.html',form = form, name = session.get('name'))

{% block content %}


{% for message in get_flashed_messages() %}


{{ message }}

{% endfor %}
{% block page_content %}{% endblock %}

{% endblock %}

你可能感兴趣的:(python flask web开发实战 页面消息提醒 常用)