librelist archives

« back to archive

overloading existing templates

overloading existing templates

From:
Jake Coffman
Date:
2011-12-06 @ 18:19
Hello flask mailing list!

I'm using Blueprints to make a modular Flask application, which seems to
work very well for adding new routes and templates. However, I would like
to modify another template's rendered results from inside a different
Blueprint, a sort of template rendering pipeline.

So for example, my core Blueprint provides an index.html template and view
which renders it. I would like to create a new Blueprint which gets the
rendered result from the core view and renders some more content to it. How
would I go about doing that?

I know there are signals that I can intercept, like the template_rendered
signal, but there doesn't seem to be a way to actually change the results
of the template call.

Thanks for your help!
Jake

Re: [flask] overloading existing templates

From:
kracekumar ramaraju
Date:
2011-12-07 @ 03:15
On Tue, Dec 6, 2011 at 11:49 PM, Jake Coffman <jake.coffman@gmail.com>wrote:

> Hello flask mailing list!
>
> I'm using Blueprints to make a modular Flask application, which seems to
> work very well for adding new routes and templates. However, I would like
> to modify another template's rendered results from inside a different
> Blueprint, a sort of template rendering pipeline.
>
> So for example, my core Blueprint provides an index.html template and view
> which renders it. I would like to create a new Blueprint which gets the
> rendered result from the core view and renders some more content to it. How
> would I go about doing that?
>
> Let us consider you have 2 blue prints.
Directory structure be

app\
        app\
                admin\ =>__init__.py contains blueprint code like

admin_blueprint = Blueprint('admin', 'app',
template_folder='admin/templates')

                accountant\=> __init__.py contains another blueprint code
like
accountant_blueprint = Blueprint('accountant', 'app',
template_folder='accountant/templates')

So  index.html inside accountant/templates can be
{% extends 'admin.templates/index.html' %}
{% your content goes here, here you can change block values and etc... %}

Hope this is useful.

I know there are signals that I can intercept, like the template_rendered
> signal, but there doesn't seem to be a way to actually change the results
> of the template call.
>
> Thanks for your help!
> Jake
>



-- 
*
"Talk is cheap, show me the code" - Linus Torvalds
Winning Regards
KraceKumar.R
http://kracekumar.wordpress.com
+91-97906-58304
*
*+91-85530-29521*
*
*

Re: [flask] overloading existing templates

From:
Jake Coffman
Date:
2011-12-07 @ 05:54
Thanks for the reply.

In this example, I think I would also have to override the routes to point
to the accountant view in order for the application to serve up the latest
index.html. If I had an additional Blueprint that needed to extend index in
this same way, it would need to know also that it has already been extended
by accountant.

Another problem seems to be when the Blueprint registers with the app it
doesn't overwrite the url rules when one already exists, it just ignores
the second. So order is very important when registering Blueprints that are
extending each other.

I think perhaps Blueprints weren't meant to be this dynamic?

Jake

On Tue, Dec 6, 2011 at 9:15 PM, kracekumar ramaraju <
kracethekingmaker@gmail.com> wrote:

>
>
> On Tue, Dec 6, 2011 at 11:49 PM, Jake Coffman <jake.coffman@gmail.com>wrote:
>
>> Hello flask mailing list!
>>
>> I'm using Blueprints to make a modular Flask application, which seems to
>> work very well for adding new routes and templates. However, I would like
>> to modify another template's rendered results from inside a different
>> Blueprint, a sort of template rendering pipeline.
>>
>> So for example, my core Blueprint provides an index.html template and
>> view which renders it. I would like to create a new Blueprint which gets
>> the rendered result from the core view and renders some more content to it.
>> How would I go about doing that?
>>
>> Let us consider you have 2 blue prints.
> Directory structure be
>
> app\
>         app\
>                 admin\ =>__init__.py contains blueprint code like
>
> admin_blueprint = Blueprint('admin', 'app',
> template_folder='admin/templates')
>
>                 accountant\=> __init__.py contains another blueprint code
> like
> accountant_blueprint = Blueprint('accountant', 'app',
> template_folder='accountant/templates')
>
> So  index.html inside accountant/templates can be
> {% extends 'admin.templates/index.html' %}
> {% your content goes here, here you can change block values and etc... %}
>
> Hope this is useful.
>
> I know there are signals that I can intercept, like the template_rendered
>> signal, but there doesn't seem to be a way to actually change the results
>> of the template call.
>>
>> Thanks for your help!
>> Jake
>>
>
>
>
> --
> *
> "Talk is cheap, show me the code" - Linus Torvalds
> Winning Regards
> KraceKumar.R
> http://kracekumar.wordpress.com
> +91-97906-58304
> *
> *+91-85530-29521*
> *
> *
>
>