librelist archives

« back to archive

Using two blueprints on / and /something

Using two blueprints on / and /something

From:
Sudaraka Wijesinghe
Date:
2014-11-10 @ 11:07
I have two bluprints (b1, b2) as in following code snippet serving /one
and /two respectively.

-- code - sart --
from flask import Flask, Blueprint

b1 = Blueprint('b1', __name__)
b2 = Blueprint('b2', __name__)

@b1.route('/')
def b1_root():
    return 'This is root of Blueprint 1'

@b1.route('/page')
def b1_page():
    return 'This is page of Blueprint 1'

@b2.route('/')
def b2_root():
    return 'This is root of Blueprint 2'

@b2.route('/page')
def b2_page():
    return 'This is page of Blueprint 2'


app = Flask(__name__)
app.register_blueprint(b1, url_prefix='/one')
app.register_blueprint(b2, url_prefix='/two')

if __name__ == '__main__':
    app.run()
-- code - end --

Above works as expected serving all the routes:
/one/
/one/page
/two/
/two/page

But once I change the url prefix of say b1 from /one to just /

	app.register_blueprint(b1, url_prefix='/')

then it returns 404 for /page.
/, /two/, /two/page works fine.

Can some one please explain this behaviour and tell me what I need to
get /page working on b1 with url prefix/

Thanks.

-- 
Sudaraka Wijesinghe.
http://sudaraka.org/

Re: [flask] Using two blueprints on / and /something

From:
Dorian Hoxha
Date:
2014-11-10 @ 11:19
try removing the prefix entirely ? '/' should work then

On Mon, Nov 10, 2014 at 12:07 PM, Sudaraka Wijesinghe <
sudaraka.wijesinghe@gmail.com> wrote:

> I have two bluprints (b1, b2) as in following code snippet serving /one
> and /two respectively.
>
> -- code - sart --
> from flask import Flask, Blueprint
>
> b1 = Blueprint('b1', __name__)
> b2 = Blueprint('b2', __name__)
>
> @b1.route('/')
> def b1_root():
>     return 'This is root of Blueprint 1'
>
> @b1.route('/page')
> def b1_page():
>     return 'This is page of Blueprint 1'
>
> @b2.route('/')
> def b2_root():
>     return 'This is root of Blueprint 2'
>
> @b2.route('/page')
> def b2_page():
>     return 'This is page of Blueprint 2'
>
>
> app = Flask(__name__)
> app.register_blueprint(b1, url_prefix='/one')
> app.register_blueprint(b2, url_prefix='/two')
>
> if __name__ == '__main__':
>     app.run()
> -- code - end --
>
> Above works as expected serving all the routes:
> /one/
> /one/page
> /two/
> /two/page
>
> But once I change the url prefix of say b1 from /one to just /
>
>         app.register_blueprint(b1, url_prefix='/')
>
> then it returns 404 for /page.
> /, /two/, /two/page works fine.
>
> Can some one please explain this behaviour and tell me what I need to
> get /page working on b1 with url prefix/
>
> Thanks.
>
> --
> Sudaraka Wijesinghe.
> http://sudaraka.org/
>
>

Re: [flask] Using two blueprints on / and /something

From:
Sudaraka Wijesinghe
Date:
2014-11-10 @ 13:18
On 11/10/14 16:49, Dorian Hoxha wrote:
> try removing the prefix entirely ? '/' should work then

Thanks, that worked.