How do I make a 404 page in Flask?

I’d like to know how to create a custom 404 page while using Flask.

Maybe try coding a 404 page in html then transfer the code into flask

i dont know much about web dev but you could probably just make a custom html 404 page, and then whenever you encounter a 404 error in the backend you just redirect to that page.

Add this to your code:

def _404(e):
  return f"<h1>{e}</h1>"
  # "e" is actually the complete 404 error message
  # You can use render_template and stuff too

@RedCoder What is the purpose of a custom 404 page?

So you don’t blind your users with light mode.

Fr though, you may want to link them back to the home page or something.



If your user goes to a page that doesn’t exist, you’ll want them to just be a click away from being able to go back to the home page.

Or if you’re confused about my joke at the beginning, default error pages on flask have a “blinding” white background.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.