G
G
gpm73152017-12-07 14:19:49
Flask
gpm7315, 2017-12-07 14:19:49

Why does Flask use the extension system?

There are, for example, python libraries mako and WTForms. And there are corresponding flask extensions flask_mako, flask_wtforms. What for to do as a matter of fact the library realizing functionality of other library? Why not use the "original" libraries directly? Those.
import mako
import wtforms
... Read Flask's
docks, but did not find a clear explanation.
Help, please, to understand.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Gilfanov, 2017-12-07
@gpm7315

mako and WTForms libraries that are not tailor made for Flask.
flask_mako, flask_wtforms -- do not implement the same functionality, but should make it easier to work with mako and WTForms inside a Flask application, as well as make it easier for mako and WTForms to interact with other libraries within a Flask application.
That is, the meaning of extensions:
The first reason is explicitly stated in the Flask documentation ( flask.pocoo.org/docs/0.12/extensiondev ):
For example, flask_mako consists of 1 file ( https://github.com/benselme/flask-mako/blob/master... ) and judging by the description --
The extension does two things:
Next we see multiple imports from Flask, werkzeug and mako.
For example, debugging tools are imported from werkzeug, and exceptions from mako:

from werkzeug.debug.tbtools import Traceback, Frame, Line
...
from mako import exceptions
from mako.exceptions import RichTraceback, text_error_template

Obviously, this is in order to see distinct errors in html templates in the Flask interactive debugger (in the spirit of, "after such and such a line, the loop was expected to close through the % endfor tag"). For more details, see the code in the TemplateError class below.
Inside flask_mako, I counted only 6 single functions and 3 classes - you can figure out the purpose of the rest in a short time.
With documentation, source commenting, and entity naming in Flask and its popular extensions, it's all pretty good, most questions can be easily answered.

D
davidnum95, 2017-12-07
@davidnum95

Provides support for Mako Templates in Flask.

They are just wrappers for Flask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question