Message Flashing

Flask provides a really simple way to give feedback to a user with the flashing system.

  1. In index.html, add below block:

    
     {% with messages = get_flashed_messages() %}
       {% if messages %}
         <div class="alert alert-danger">
         <ul class=flashes>
         {% for message in messages %}
           <li>{{ message }}</li>
         {% endfor %}
         </ul>
         </div>
       {% endif %}
     {% endwith %}
    
  2. In views.py, add flash messages:
@weather.route('/update/<location>', methods=['POST', 'GET'])
def update(location):
    form = UpdateForm()
    if form.validate_on_submit():
        ....
        flash('The weather is successfully updated.')
        return render_template('update.html', form=form, dt=dt,basic=basic, detail=detail, daily=daily.daily_list, alert=False)
    else:
        flash('Can not find the location in your search history. Please go back to index page, search the location first, then update if the data are wrong!')
        return render_template('update.html', form=form, alert=True)

results matching ""

    No results matching ""