I'm building a Python/Flask (fully ajax, without full page reloading) web application and I change the content of my master page when the sharp ("#") sign on the url change (Ben Alman, HashChange event)
I would like to catch all Error-404 to append an error page in my master page
Taking the following code in consideration
from flask import Flask, redirect
#WebServerGatewayInterface
class WSGI():
def __init__(self):
self.app = Flask(__name__)
self.app.debug = True
wsgi = WSGI()
@wsgi.app.route("/")
def Home():
return "Home"
@wsgi.app.route("/Contact")
def Contact():
return "Contact"
@wsgi.app.errorhandler(404)
def PageNotFound(error):
return "PageNotFound"
if __name__ == '__main__':
wsgi.app.run(host='127.0.0.1', port=7777)
I would like to understand why when I add a non-exising URL after the sharp ("#") sign, it isn't trapped by the errorhandler ?
E.g.
127.0.0.1:7777
#It returns "Home"
127.0.0.1:7777/Contact
#It returns "Contact"
127.0.0.1:7777/Aasdasdasdasd
#It returns "PageNotFound"
127.0.0.1:7777/#/asdsaasdasdasdas
#It returns "Home", which is not right since this URL doesn't exist
127.0.0.1:7777/#!/asdsaasdasdasdas
#It returns "Home", not ok...
127.0.0.1:7777/#!/Contact
#It returns "Home", not ok...
Everything after the
#
forms the fragment identifier of a resource and is handled client side. In the normal course of operation, the fragment identifier is never sent to the server:If a server is ever sent a fragment identifier in a URL, it must ignore this part of the URL. It is not part of the path, and thus Flask just sees
127.0.0.1:7777/
for all your sample URLs with a fragment.