Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

How to do it...

Create a method that is decorated with errorhandler() and renders the 404.html template whenever the 404 Not Found error occurs:

@app.errorhandler(404) 
def page_not_found(e): 
    return render_template('404.html'), 404 

The following lines of code represent the flask_catalog_template/my_app/templates/404.html template, which is rendered in case of 404 errors:

{% extends 'home.html' %} 
 
{% block container %} 
  <div class="top-pad"> 
    <h3>Hola Friend! Looks like in your quest you have reached a        location which does not exist yet.</h3> 
    <h4>To continue, either check your map location (URL) or go        back <a href="{{ url_for('catalog.home') }}">home</a></h4> 
  </div> 
{% endblock %} 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content