38 lines
807 B
Python
38 lines
807 B
Python
import functools
|
|
import io
|
|
|
|
import flask
|
|
|
|
from werkzeug.wsgi import FileWrapper
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
|
|
class HTTPError(flask.Response, Exception):
|
|
def __init__(self, *args, status_code, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.status_code = status_code
|
|
|
|
|
|
def handle_errors(func):
|
|
@functools.wraps(func)
|
|
def wrapped(*args, **kwargs):
|
|
try:
|
|
return func(*args, **kwargs)
|
|
except HTTPError as r:
|
|
return r, r.status_code
|
|
except Exception as e:
|
|
print(e)
|
|
return flask.Response("Oh no! Hi ha hagut un error en el servidor :(", status="Internal error"), 500
|
|
|
|
return wrapped
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return flask.render_template("./index.html")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|