librelist archives

« back to archive

Import problem using blueprints

Import problem using blueprints

From:
Philippe Ndiaye
Date:
2013-08-07 @ 19:47
Hi,

I have a Flask application using blueprints to separate the different parts
of it (like the backend and the frontend). Following the documentation, i
declare my blueprint this way:

    from flask import Blueprint
    admin = Blueprint('admin', __name__, template_folder='templates')

and register them this way in my app root __init__.py file:
    from apps.admin import admin
    app.register_blueprint(admin, url_prefix='/admin')

But, wanting to group my blueprint's stuffs in different files according to
their role, i created an account.py file in my blueprint folder that
contains all the routes related to account management (login, password
recovery ...). But, unless i import this account.py module in my blueprint
__init__.py file, it does not find the routes declared into it. I always
some 404 errors and

Any idea of what can cause that ? Knowing it would normally work without
importing the submodules which are importing yet the blueprint object to
declare the routes.
-- 
**
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux SysAdmin  | Python Programmer
http://iamphinson.com || me@iamphinson.com
Twitter: http://twitter.com/phndiaye

Re: [flask] Import problem using blueprints

From:
Jaime Wyant
Date:
2013-08-07 @ 20:23
Your routes aren't registered until you do something like ..

@admin.route( ... )

If all of your routes are defined in another module, they won't be created
until you import that module.  This occurs because that code isn't executed
until the module is imported.


On Wed, Aug 7, 2013 at 2:47 PM, Philippe NDIAYE <phndiaye@gmail.com> wrote:

> Hi,
>
> I have a Flask application using blueprints to separate the different
> parts of it (like the backend and the frontend). Following the
> documentation, i declare my blueprint this way:
>
>     from flask import Blueprint
>     admin = Blueprint('admin', __name__, template_folder='templates')
>
> and register them this way in my app root __init__.py file:
>     from apps.admin import admin
>     app.register_blueprint(admin, url_prefix='/admin')
>
> But, wanting to group my blueprint's stuffs in different files according
> to their role, i created an account.py file in my blueprint folder that
> contains all the routes related to account management (login, password
> recovery ...). But, unless i import this account.py module in my
> blueprint __init__.py file, it does not find the routes declared into it.
> I always some 404 errors and
>
> Any idea of what can cause that ? Knowing it would normally work without
> importing the submodules which are importing yet the blueprint object to
> declare the routes.
> --
> **
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux SysAdmin  | Python Programmer
> http://iamphinson.com || me@iamphinson.com
> Twitter: http://twitter.com/phndiaye
>



-- 
"Government does not solve problems; it subsidizes them."
Ronald Reagan

Re: [flask] Import problem using blueprints

From:
Harish N
Date:
2013-08-08 @ 16:14
Can you try this?
add this.
admin/__init__.py
from .views import admin

admin/views.py
From flask import Blueprint

admin = Blueprint ('admin', __name__, template_folder=templates)

app.py
from admin import admin
from flask import register_blueprint

# initialize your app here .

app.register_blueprint (admin, url_prefix='/admin')
On Aug 8, 2013 1:19 AM, "Philippe NDIAYE" <phndiaye@gmail.com> wrote:

> Hi,
>
> I have a Flask application using blueprints to separate the different
> parts of it (like the backend and the frontend). Following the
> documentation, i declare my blueprint this way:
>
>     from flask import Blueprint
>     admin = Blueprint('admin', __name__, template_folder='templates')
>
> and register them this way in my app root __init__.py file:
>     from apps.admin import admin
>     app.register_blueprint(admin, url_prefix='/admin')
>
> But, wanting to group my blueprint's stuffs in different files according
> to their role, i created an account.py file in my blueprint folder that
> contains all the routes related to account management (login, password
> recovery ...). But, unless i import this account.py module in my
> blueprint __init__.py file, it does not find the routes declared into it.
> I always some 404 errors and
>
> Any idea of what can cause that ? Knowing it would normally work without
> importing the submodules which are importing yet the blueprint object to
> declare the routes.
> --
> **
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux SysAdmin  | Python Programmer
> http://iamphinson.com || me@iamphinson.com
> Twitter: http://twitter.com/phndiaye
>