librelist archives

« back to archive

How to include custom Jinja extensions?

How to include custom Jinja extensions?

From:
Swaroop C H
Date:
2011-06-07 @ 03:07
Hi everyone,

Is there a way to include custom Jinja extensions in Flask, such as
the FragmentCacheExtension
example <http://jinja.pocoo.org/docs/extensions/#example-extension> ?

Thanks!
Swaroop

Re: [flask] How to include custom Jinja extensions?

From:
Adam Patterson
Date:
2011-06-07 @ 03:36
http://flask.pocoo.org/docs/api/#flask.Flask.jinja_options

On Mon, Jun 6, 2011 at 10:07 PM, Swaroop C H <swaroop@swaroopch.com> wrote:
> Hi everyone,
> Is there a way to include custom Jinja extensions in Flask, such as
> the FragmentCacheExtension example ?
> Thanks!
> Swaroop

Re: [flask] How to include custom Jinja extensions?

From:
Simon Sapin
Date:
2011-06-07 @ 06:55
Le 07/06/2011 05:36, Adam Patterson a écrit :
> http://flask.pocoo.org/docs/api/#flask.Flask.jinja_options
>
> On Mon, Jun 6, 2011 at 10:07 PM, Swaroop C H<swaroop@swaroopch.com>  wrote:
>> Hi everyone,
>> Is there a way to include custom Jinja extensions in Flask, such as
>> the FragmentCacheExtension example ?
>> Thanks!
>> Swaroop

Note: since the jinja_options is immutable, you need to inherit from 
Flask and build a new ImmutableDict based on Flask.jinja_options + your 
new config.

Regards,
-- 
Simon Sapin

Re: [flask] How to include custom Jinja extensions?

From:
Ross Lawley
Date:
2011-06-07 @ 07:33
On app creation I use add_extension to load extra extensions eg:

    app = Flask(app_name)

app.jinja_env.add_extension('helpers.jinja2.htmlcompress.SelectiveHTMLCompress')


Ross

On Tue, Jun 7, 2011 at 7:55 AM, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 07/06/2011 05:36, Adam Patterson a écrit :
> > http://flask.pocoo.org/docs/api/#flask.Flask.jinja_options
> >
> > On Mon, Jun 6, 2011 at 10:07 PM, Swaroop C H<swaroop@swaroopch.com>
>  wrote:
> >> Hi everyone,
> >> Is there a way to include custom Jinja extensions in Flask, such as
> >> the FragmentCacheExtension example ?
> >> Thanks!
> >> Swaroop
>
> Note: since the jinja_options is immutable, you need to inherit from
> Flask and build a new ImmutableDict based on Flask.jinja_options + your
> new config.
>
> Regards,
> --
> Simon Sapin
>

Re: [flask] How to include custom Jinja extensions?

From:
Adam Patterson
Date:
2011-06-07 @ 15:24
Oh nice Ross. I didn't know about that.

On Tue, Jun 7, 2011 at 2:33 AM, Ross Lawley <ross.lawley@gmail.com> wrote:
> On app creation I use add_extension to load extra extensions eg:
>     app = Flask(app_name)
>
> app.jinja_env.add_extension('helpers.jinja2.htmlcompress.SelectiveHTMLCompress')
>
>
> Ross
> On Tue, Jun 7, 2011 at 7:55 AM, Simon Sapin <simon.sapin@exyr.org> wrote:
>>
>> Le 07/06/2011 05:36, Adam Patterson a écrit :
>> > http://flask.pocoo.org/docs/api/#flask.Flask.jinja_options
>> >
>> > On Mon, Jun 6, 2011 at 10:07 PM, Swaroop C H<swaroop@swaroopch.com>
>> >  wrote:
>> >> Hi everyone,
>> >> Is there a way to include custom Jinja extensions in Flask, such as
>> >> the FragmentCacheExtension example ?
>> >> Thanks!
>> >> Swaroop
>>
>> Note: since the jinja_options is immutable, you need to inherit from
>> Flask and build a new ImmutableDict based on Flask.jinja_options + your
>> new config.
>>
>> Regards,
>> --
>> Simon Sapin
>
>