librelist archives

« back to archive

Using Blueprints intelligently

Using Blueprints intelligently

From:
Adam Pointer
Date:
2011-12-21 @ 11:25
Hi,

I don't know if this is possible but I have several blueprints that 
manage CRUD on several different page types. I want to take out a common 
function that needs to be in each one and create a separate blueprint 
from it, this will be called something like 'metas'. I want something 
like this:

/pages -> Pages blueprint
/pages/metas -> Metas blueprint
/pages/{pagename} -> Pages blueprint
/pages/{pagename}/metas -> Metas blueprint
/categories -> Categories blueprint
/categories/metas -> Metas blueprint
/categories/{category name} -> Categories blueprint
/categories/{category name}/metas -> Metas blueprint

So that appending /metas to the URL of any page will return the correct 
'metas' template pertaining to that page.

How would I go about registering the URLs for my blueprints correctly? 
Would I have to register the new blueprint multiple times and if so how 
do you use url_for() to get the URL for blueprints that have been 
registered multiple times with different url_prefixes?

Re: [flask] Using Blueprints intelligently

From:
kracekumar ramaraju
Date:
2011-12-21 @ 16:51
Hi

<adam.pointer@gmx.com> wrote:

> Hi,
>
> I don't know if this is possible but I have several blueprints that
> manage CRUD on several different page types. I want to take out a common
> function that needs to be in each one and create a separate blueprint
> from it, this will be called something like 'metas'. I want something
> like this:
>
> /pages -> Pages blueprint
> /pages/metas -> Metas blueprint
> /pages/{pagename} -> Pages blueprint
> /pages/{pagename}/metas -> Metas blueprint
> /categories -> Categories blueprint
> /categories/metas -> Metas blueprint
> /categories/{category name} -> Categories blueprint
> /categories/{category name}/metas -> Metas blueprint
>

Suggestion:

/metas/ =>meta blueprint
/categories/ => categories blueprint
/pages/ =>  pages blueprint.

meta_blueprint = Blueprint('metas','__name__', url_prefix='/metas',
template_folder="/path/to/template)



> So that appending /metas to the URL of any page will return the correct
> 'metas' template pertaining to that page.
>
> How would I go about registering the URLs for my blueprints correctly?
> Would I have to register the new blueprint multiple times and if so how
> do you use url_for() to get the URL for blueprints that have been
> registered multiple times with different url_prefixes?
>

You need to import metas blueprint where you are using url_for
url_for('metas.func_name', _external='True')
This should probably work but I haven't tried.

I have written one such application but under construction, but you can
learn about blueprint from here
https://github.com/kracekumar/Blaze/blob/master/blaze/world/__init__.py


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