r/flask • u/sprocketerdev • 10d ago
Ask r/Flask Displaying HTTP response code in Jinja
I want to display the response code sent from my Flask backend (e.g. 400 200 201 etc.) in Jinja - how can I access this?
1
Upvotes
r/flask • u/sprocketerdev • 10d ago
I want to display the response code sent from my Flask backend (e.g. 400 200 201 etc.) in Jinja - how can I access this?
1
u/1NqL6HWVUjA 10d ago
Assuming you're dealing with an instance of a Werkzeug
HTTPException
— which you are if you're doing something likeabort(404)
— then thecode
attribute contains the HTTP status code.Here's a relatively minimal working example of custom error handlers that render a template: