librelist archives

« back to archive

Blueprint like structure but with shared templates/static dir

Blueprint like structure but with shared templates/static dir

Charles Law
2014-06-16 @ 23:24
I am working on an application that has a Blueprint for an admin page.  We
should be able to add additional tabs to the admin page depending on the
specific deployment.  I.e. a deployment might be going to a datacenter so
it has an extra tab for access to network switch/router admin.

I currently have some small, slightly hacky code making this work, but I'd
like to move to a library/feature more widely used if it exists.  I have
not been able to find anything yet though.  I am looking for something like
Blueprints, but not as independent from the parent Flask app.  Basically,
it should be able to share things like templates & static files.  Does
anyone know if this exists?  If something does not exist, I would like to
share my code so that others may use & improve it.

So in my hacky code I have these called Components.  There are some
trickier parts that prevent me from using Blueprints (& adding support for
Blueprints instead of Blueprints) instead of Components.  Any feedback is

 - The base template (includes a tab layout, css, etc) comes from the
parent Blueprint, so the Components need access to that.  I solve this
using Jinja's FileSystemLoader which accepts lists of folders.  The parent
Blueprint (a special modified Blueprint) sends a list of folders including
itself & the components template folders and everything is accessible
everywhere :).

 - The base template takes some variables calculated in the base Blueprint.
 I cheat by having the base blueprint call the Component's endpoints as
passing these values in.  I don't like how I have this, especially since
the Component view functions need to accept these parameters - even if they
are just a RESTful endpoint.

- Static files are a tricky.  The Component has it's own static folder, so
I wrote some code that goes through Blueprint & then Component static
folders and serves the first file it finds.  The URI of the static file
does not say anything about which Component/Blueprint owns the file.

- Routes: When the Component is registered, no prefix is added, so routes
are the same level as the Blueprint's.  It made slightly more sense for me
since each tab is /[Blueprint]/tabname so the component tabs URIs look like
the rest of the tabs.