![]() ![]() > SITEMAP has disadvantages For big apps, its nice to have a single routes. Rather than calling app.before_request, you can call blueprint.before_request and it will work only for that blueprint. Also (small issue) You cant add blueprint specific middleware. app. > BLUEPRINT are nice, but have issues: When you create a blueprint, for a sub app, you cant set error handlers. How can i pass a variable to a blueprint from the apps main file. If you can solve it using simple python(decorators), solve it using Python. At least you can still use WSGI middleware. > MIDDLEWARE: Flask promotes writing middleware as decorators functions, while it looks nice, it not really useable anywhere else, and its not really a standard. Werkzeug does the same thing, except it does it more robustly. I have had this discussion with someone else before:įWIW, flask's "from flask import request" never had been a blocker for me, whereas django's injected request variable had made me write middleware to preseve requests as thread locals so that I can access it elsewhere. Any other web framework that I know does it like this.įlask's request is not global. > GLOBALS: Flask has a lot of globals (from flask import g, request, current_user, etc.) A better web handler function looks like this handle(request) -> response. Haven't used flask in some time now, but most of your objections are missing the mark. Also it promotes circular imports:įrom init import blueprint #circular import!Īssert view # ensure the handlers are initiallized The is nice to use initially, but imho for big apps it becomes messy. Or use a sitemap where you bind functions to paths.įor big apps, its nice to have a single routes.py file where you can see all urls the app supports, and which methods to handle those. They only work on app level.Īlso (small issue) You cant add blueprint specific middleware.īetter way to create 'sub apps': Use a new WSGI App. When you create a blueprint, for a sub app, you cant set error handlers. Flask is not functional, its inherently statefull with globals.įlask promotes writing middleware as decorators functions, while it looks nice, it not really useable anywhere else, and its not really a standard. Flask promotes touching the 'request' object everywhere. Any other web framework that I know does it like this. py file, or package) and try to detect an. If FLASKAPP is not set, the command will try to import app or wsgi (as a. So some things i don"t like about flask:ĭisclaimer: You can architect beautiful apps in apps, its just easy todo it wrong.įlask has a lot of globals (from flask import g, request, current_user, etc.)Ī better web handler function looks like this handle(request) -> response. FLASKAPP'hello:createapp ('dev')' The createapp factory in hello is called with the string 'dev' as the argument. from flask import Blueprint, Response from dependencyinjector. I worked with numerous python web frameworks, mainly webapp2 and flask. Im trying to inject dependencies to a flask blueprint: blueprints.py. Blueprints can greatly simplify how large applications work and provide a central means for Flask extensions to register operations on applications. Logs are also ready to send to ELK using a filebeat.While flask is a nice framework, it has some problems. Flask uses a concept of blueprints for making application components and supporting common patterns within an application or across applications. I normally deploy it in production using a nginx as a reverse proxy and n replicas of my api. I also like to use a library to help me to work with psycopg2: a library ( ) created by me a long time ago.Īnd that’s all. This connection is a raw psycopg2 connection. We also can create the connection using a constructor. For example, we can use a function decorator to inject the connection (in this case the connection named DEFAULT) in the function signatura. We can obtain our database connection in diverse ways. Return db2.fetch_all(SQL_USERS, dict(name=name)) # Example of how to obtain new connection from database name. # Create new transaction from connection injected with a decoratorĭb.upsert('users', dict(email=email), dict(name=name)) From lib.db import get_db_from_conn, get_conn_from_dbnameįrom lib.decorators import use_schema, inject_connįrom. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |