-2

I want to add custom 404 page.

I have this code:

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

But It doesn't work I still get

2017-10-10 09:24:04,983: File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 61, in get_source 2017-10-10 09:24:04,983: raise TemplateNotFound(template)

UPD: I HAVE 404.html file in my templates folder! enter image description here

user2950593
  • 9,233
  • 15
  • 67
  • 131

2 Answers2

2

its like the template cannot be found

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

It looks like the template is not where you expect to find it.

Can you try to put in /static and read it from there?

@app.errorhandler(404)
def page_not_found(e):
    return send_from_directory("static", "404.html"), 404
Alex Poca
  • 2,406
  • 4
  • 25
  • 47