issues's People
issues's Issues
Not able to see custom 404 page
PROBLEM SUMMARY
I created a custom 404 handler for Flask and it still showed the in-built 404 page for a non-existing url
EXPECTED BEHAVIOR
After creating a custom handler for the app I should have gotten something like this
CURRENT BEHAVIOR
But I got this,
CONTEXT/ENVIRONMENT/CODE SNIPPET
Here is what I had written in the views.py
module where I had declared the blueprint.
from flask import Blueprint
.
.
.
detect_faces = Blueprint(__name__, 'detect_faces')
.
.
.
@detect_faces.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
SOLUTION
The error handling is done by the app
not by the blueprint
; so move the error handling to the __init__.py
module where all the blueprints are registered. See the modified __init__.py
import os
from os import path
from flask import Flask
from face_detector.detect.views import detect_faces
CWD = os.getcwd()
INSTANCE_PATH = path.join(CWD, 'instance')
app = Flask(__name__, instance_path=INSTANCE_PATH, instance_relative_config=True)
app.register_blueprint(detect_faces)
MODIFIED VERSION of __init__.py
import os
from os import path
from flask import Flask, render_template
from face_detector.detect.views import detect_faces
CWD = os.getcwd()
INSTANCE_PATH = path.join(CWD, 'instance')
app = Flask(__name__, instance_path=INSTANCE_PATH, instance_relative_config=True)
app.register_blueprint(detect_faces)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
REFERENCES
https://stackoverflow.com/questions/32039583/flask-custom-error-page-500-not-working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.