![]() jinja_loader if loader is not None : yield blueprint, loader jinja_loader if loader is not None : yield self. If the template is not found there, it then continues to yield the rest of the loaders created for each blueprint that has a template_folder=”something” option set: def _iter_loaders ( self, template ): loader = self. Upon a call to render_template this loader first yields the familiar app.jinja_loader to be used to load a template. In reality, something called a DispatchingJinjaLoader is created in the main Flask application. The FileSystemLoader stored at jinja_loader is not actually the top Jinja loader for a Flask application. On instantiation of a Flask application with a call to Flask(_name_), Flask creates a Jinja FileSystemLoader that points to the root templates folder in the _PackageBoundObject class (which both a Flask application and a Blueprint inherit from) called jinja_loader, which you would usually access as app.jinja_loader. Unfortunately the reality is not so simple. It seems intuitive that from within the “users” blueprint a call to render_template(“index.html”) would render the template located in its templates folder which perhaps would extend the base.html template. You might hope that this would allow you to create an application structured as shown: app/ Luckily (at least I thought at the time), Flask allows you to specify a templates folder when instantiating a Blueprint, as shown: mod = Blueprint ( 'users', _name_, url_prefix = '/users', template_folder = "templates" ) This would make things more modular, as a single blueprint could be deleted from or added to an application without needing to mess around with another set of templates being copied into the main templates folder. On a recent project, I decided I wanted to start storing an individual templates folder inside ofĮach blueprint’s Python module instead of jumbling them all together into a single folder. ![]() A side effect of this is that for large applications with many blueprints you end up with a templates folder that is a jumble of subdirectories, each relating to a specific blueprint. If you want to add your Socket.IO stuff in the same package as you are hosting a blueprint, feel free, but the blueprint itself does not provide any benefits to Socket.IO.A lot of the work I do involves large Flask applications structured in the manner described by the excellent Digital Ocean guide How To Structure Large Flask Applications. From the Socket.IO point of view a blueprint is just a Python package. There is no flexibility in design to use this library with blueprints.īlueprints would not help in any way with Socket.IO. I went out of my way to support the most commonly used websocket implementations. The underlying websocket implementation is the same, so what do you think is missing?įrom your response I get the opposite, unexpected answer that this library is only working in one way This is why I really did not understand what you were asking. Flask-SocketIO also includes support for gevent and gevent-websocket. This extension uses gevent and gevent-websocket internally. The example that you linked uses the abandoned Flask-Sockets extension. Was under the the apparently wrong impression that when I wanted to use socket.io integration with websockets in Flask on App Engine, this library might be useful
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |