librelist archives

« back to archive

I'm having problems with Blueprints

I'm having problems with Blueprints

From:
Kenji Wellman
Date:
2011-10-14 @ 02:43
Hi,
I'm using Flask 0.8. I've been trying to use Blueprints with my app, but I
have a couple of issues.

1. How do I extend from a template in my blueprint template folder? When I
use the "extends" template command in a blueprint template, flask seems to
search for the template in the the main app template folder and not the
blueprint folder. The render_template command works fine, and searches for
templates in the "template_folder" value I passed to the blueprint
constructor, but then it seems to be ignored within the template, which I
find confusing.

2. I can't seem use two blueprints in one app. When I register both of them,
flask seems to ignore the "template_folder" setting I pass to the blueprint
constructor. Using just one blueprint works fine (except for the issue
above).

Thanks for your help.

Re: [flask] I'm having problems with Blueprints

From:
Oliver Berger
Date:
2011-10-14 @ 12:53
Hi Kenji,

you have to prepare a namespace-like directory structure in your
blueprint template folder e.g.:

bp/
   templates/
             bp/
                layout.html
                index.html
                edit.html
                ...
templates/
          layout.html
          ...
static/
       ...
...

your edit.html contains something like: {% extends "bp/layout.html" %}

If you have an app template called layout.html and you have the same
file in your blueprint templates then flask is using the one from the app.

Think of it as if flask is merging all the template folders together.

I guess this will also fix your second issue.


regards,
Oliver


On 14.10.2011 04:43, Kenji Wellman wrote:
> Hi,
> I'm using Flask 0.8. I've been trying to use Blueprints with my app, but
> I have a couple of issues.
> 
> 1. How do I extend from a template in my blueprint template folder? When
> I use the "extends" template command in a blueprint template, flask
> seems to search for the template in the the main app template folder and
> not the blueprint folder. The render_template command works fine, and
> searches for templates in the "template_folder" value I passed to the
> blueprint constructor, but then it seems to be ignored within the
> template, which I find confusing.
> 
> 2. I can't seem use two blueprints in one app. When I register both of
> them, flask seems to ignore the "template_folder" setting I pass to the
> blueprint constructor. Using just one blueprint works fine (except for
> the issue above).
> 
> Thanks for your help.

Re: [flask] I'm having problems with Blueprints

From:
Kenji Wellman
Date:
2011-10-15 @ 02:15
Thanks. That works.

On Fri, Oct 14, 2011 at 8:53 AM, Oliver Berger
<oliver@digitalarchitekt.de>wrote:

> Hi Kenji,
>
> you have to prepare a namespace-like directory structure in your
> blueprint template folder e.g.:
>
> bp/
>   templates/
>             bp/
>                layout.html
>                index.html
>                edit.html
>                ...
> templates/
>          layout.html
>          ...
> static/
>       ...
> ...
>
> your edit.html contains something like: {% extends "bp/layout.html" %}
>
> If you have an app template called layout.html and you have the same
> file in your blueprint templates then flask is using the one from the app.
>
> Think of it as if flask is merging all the template folders together.
>
> I guess this will also fix your second issue.
>
>
> regards,
> Oliver
>
>
> On 14.10.2011 04:43, Kenji Wellman wrote:
> > Hi,
> > I'm using Flask 0.8. I've been trying to use Blueprints with my app, but
> > I have a couple of issues.
> >
> > 1. How do I extend from a template in my blueprint template folder? When
> > I use the "extends" template command in a blueprint template, flask
> > seems to search for the template in the the main app template folder and
> > not the blueprint folder. The render_template command works fine, and
> > searches for templates in the "template_folder" value I passed to the
> > blueprint constructor, but then it seems to be ignored within the
> > template, which I find confusing.
> >
> > 2. I can't seem use two blueprints in one app. When I register both of
> > them, flask seems to ignore the "template_folder" setting I pass to the
> > blueprint constructor. Using just one blueprint works fine (except for
> > the issue above).
> >
> > Thanks for your help.
>
>