How to configure mako templates with Flask to get thrown exceptions?

I like mako and wish it was easier to integrate with the flask. I install the flask-mako extension , but quickly found that instead of a very nice flugg debugger , creating an easily understandable trace, as it was with jinja, I get an almost useless version with small descriptions and inaccurate line numbers (I would provide some convincing evidence, but I already deleted them).

This thread describes a way to configure mako with better exception handling, which I suppose was my problem, but from what I can say, it seems I need to run try / except for each of my url functions?

There is no way to turn this exception handling "always on", so will the debug flask be used without extra effort?

Several places mention how easy it is to swap jinja / mako in a flask, but I find that it is not. Hope I missed something ...

+4
source share
1 answer

flask-mako is a very simple package. Instead of wrapping each of your rendering calls with try: except :, I suggest you use flask-mako instead of fork, and in flaskext / mako.py wrap the rendering call (line 53 of the current host) with mako try except. A quick transition can be found at: https://github.com/jd-boyd/flask-mako

However, although this makes the error in the mako template much easier to find, it still does not allow the use of the flag debugger to debug mako templates.

0
source

Source: https://habr.com/ru/post/1414995/


All Articles