Discussion:
Define jinja2 as default engine in a merged bottle app
'Felix H' via bottlepy
2014-10-20 20:47:28 UTC
Permalink
I'm trying to build a small python app based on the bottle framework.
First some information about the structure:

/application
app.py
/controllers
content.py
media.py
settings.py
/models
/views


The python files in the controllers directory each contains a bottle app
which will be all merged to a single one in the app.py - I'm trying to
simulate the mvc pattern. For these apps I'm using the jinja2 template
engine with some custom filters e.g. for formatting a timestamp. So every
'small' app has an import like this:

from Bottle import jinja2_view as view



Therefore I have to define the custom filters in each app - not really
satisfying.
Is there a possibility to define these custom filters just one time and use
them in all apps/templates?

--
Thanks and best regards,
Felix
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Felix H' via bottlepy
2014-10-21 05:24:06 UTC
Permalink
Currently created a 'custom.py' with custom filters and jinja2_view as
view. Import this file in the app files. It's working, but is there a
prettier solution?

Greetings!
Post by 'Felix H' via bottlepy
I'm trying to build a small python app based on the bottle framework.
/application
app.py
/controllers
content.py
media.py
settings.py
/models
/views
The python files in the controllers directory each contains a bottle app
which will be all merged to a single one in the app.py - I'm trying to
simulate the mvc pattern. For these apps I'm using the jinja2 template
engine with some custom filters e.g. for formatting a timestamp. So every
from Bottle import jinja2_view as view
Therefore I have to define the custom filters in each app - not really
satisfying.
Is there a possibility to define these custom filters just one time and
use them in all apps/templates?
--
Thanks and best regards,
Felix
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcel Hellkamp
2014-10-21 18:16:56 UTC
Permalink
Define this somewhere:

my_view = functools.partial(bottle.view,
template_adapter = bottle.Jinja2Template,
template_settings = {
'filters': {
'filter_name': filter_callable
}
})

and import it where you need it. That's the easiest way I can think of.
Post by 'Felix H' via bottlepy
I'm trying to build a small python app based on the bottle framework.
|/application
app.py
/controllers
content.py
media.py
settings.py
/models
/views|
The python files in the |controllers| directory each contains a bottle
app which will be all merged to a single one in the |app.py| - I'm
trying to simulate the mvc pattern. For these apps I'm using the
jinja2 template engine with some custom filters e.g. for formatting a
|
|from Bottle import jinja2_viewas view|
|
Therefore I have to define the custom filters in each app - not really
satisfying.
Is there a possibility to define these custom filters just one time
and use them in all apps/templates?
--
Thanks and best regards,
Felix
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Felix H' via bottlepy
2014-10-21 19:56:03 UTC
Permalink
Sehr sehr nice! Danke dir! :)
Post by Marcel Hellkamp
my_view = functools.partial(bottle.view,
template_adapter = bottle.Jinja2Template,
template_settings = {
'filters': {
'filter_name': filter_callable
}
})
and import it where you need it. That's the easiest way I can think of.
I'm trying to build a small python app based on the bottle framework.
/application
app.py
/controllers
content.py
media.py
settings.py
/models
/views
The python files in the controllers directory each contains a bottle app
which will be all merged to a single one in the app.py - I'm trying to
simulate the mvc pattern. For these apps I'm using the jinja2 template
engine with some custom filters e.g. for formatting a timestamp. So every
from Bottle import jinja2_view as view
Therefore I have to define the custom filters in each app - not really
satisfying.
Is there a possibility to define these custom filters just one time and
use them in all apps/templates?
--
Thanks and best regards,
Felix
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...