Procházet zdrojové kódy

Very basic attempt at exception printing.

pull/24/head
Ben Kurtovic před 10 roky
rodič
revize
19ad246a12
1 změnil soubory, kde provedl 12 přidání a 1 odebrání
  1. +12
    -1
      app.fcgi

+ 12
- 1
app.fcgi Zobrazit soubor

@@ -6,7 +6,7 @@ from logging import DEBUG
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler


from flask import Flask, g, request from flask import Flask, g, request
from flask.ext.mako import MakoTemplates, render_template
from flask.ext.mako import MakoTemplates, render_template, TemplateError
from flup.server.fcgi import WSGIServer from flup.server.fcgi import WSGIServer


from copyvios.cookies import parse_cookies from copyvios.cookies import parse_cookies
@@ -19,6 +19,14 @@ app.logger.addHandler(TimedRotatingFileHandler(
"logs/app.log", when="D", interval=1, backupCount=7)) "logs/app.log", when="D", interval=1, backupCount=7))
app.logger.info(u"Flask server started " + asctime()) app.logger.info(u"Flask server started " + asctime())


def debug_exceptions(func):
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except TemplateError as exc:
return "<pre>" + exc.text + "</pre>"
return inner

@app.before_request @app.before_request
def prepare_cookies(): def prepare_cookies():
cookie_string = request.environ.get("HTTP_COOKIE") cookie_string = request.environ.get("HTTP_COOKIE")
@@ -40,14 +48,17 @@ def write_access_log(response):
return response return response


@app.route("/") @app.route("/")
@debug_exceptions
def index(): def index():
return render_template("index.mako") return render_template("index.mako")


@app.route("/settings", methods=["GET", "POST"]) @app.route("/settings", methods=["GET", "POST"])
@debug_exceptions
def settings(): def settings():
return render_template("settings.mako") return render_template("settings.mako")


@app.route("/debug") @app.route("/debug")
@debug_exceptions
def debug(): def debug():
return render_template("debug.mako") return render_template("debug.mako")




Načítá se…
Zrušit
Uložit