Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:09:26+00:00 2026-06-10T19:09:26+00:00

Flask has a good error handler by using abort() or when the error truly

  • 0

Flask has a good error handler by using abort() or when the error truly occurred.

From Flask documentation there is an example for error 404 handler:

@app.errorhandler(404)
def not_found(error):
    return render_template('404.html'), 404

So, I tried to create custom error code like

if False:
    abort(777)

@app.errorhandler(777)
def something_is_wrong(error):
    return render_template('777.html'), 777

But it does not work and the Werkzeug debugger says: LookupError: no exception for 777

I found this question which says I should do it like this:

if False:
    return '777 error', 777

Unfortunately, the code above produce white-screen, even the Werkzeug debugger does not come out

I know I can simply do:

if False:
    return render_template('777.html')

But it will make the code cleaner if I use the abort(). Is there any way to create custom error code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:09:27+00:00Added an answer on June 10, 2026 at 7:09 pm

    The list of possible HTTP status codes is fixed by the Internet Assigned Numbers Authority, so you cannot add a custom one. Werkzeug recognizes this and tries to stop you sending a meaningless code to the browser. Look through the list of status codes to find one that matches your error and use that one.

    Edit: Adding status codes to Werkzeug/Flask

    import werkzeug.exceptions as ex
    from flask import Flask, abort
    
    class PaymentRequired(ex.HTTPException):
        code = 402
        description = '<p>You will pay for this!</p>'
    
    abort.mappings[402] = PaymentRequired
    
    app = Flask(__name__)
    
    @app.route('/')
    def mainpage():
        abort(402)
    
    @app.errorhandler(402)
    def payme(e):
        return 'Pay me!'
    
    app.run()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good way to determine if a person has a popup blocker
Is there any good control or plug-in for uploading multiple photos with preview? As
Anybody know of a good tutorial about flask-principal? I'm trying to do authentication and
good day stackoverflow! im not sure if any of you has tried this but
I'm trying to find a good approach for tracking event data from videos that
I am a programmer with a relatively good background programming in ActionScript using Flash
I am using flask-peewee to build a new project. Also I am using the
Almost every flash player has an option to display how much of buffer (or
I have a Flash movie which has a number of actionscript 2 functions which
I downloaded a flash player that has changeable settings. I am trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.