librelist archives

« back to archive

MethodView and url_prefix for blueprint

MethodView and url_prefix for blueprint

From:
Alex K
Date:
2012-06-07 @ 10:34
I try rewrite my functions of views to MethodView in blueprints.

Seems url_prefix for blueprint don't work?

app.register_blueprint(statistic.mod, url_prefix='/statistic',
name='statistic')

from flask.views import MethodView

class TestView(MethodView):
    def get(self):
        print('TestView called')

app.add_url_rule('/test', view_func=TestView.as_view('test_view'),
    methods=['GET',])

Then I go to url '/statistic/test' and it not work (404 not found).

But in '/test' it work.

It's bug or feature?

Thanks!

Re: [flask] MethodView and url_prefix for blueprint

From:
Simon Sapin
Date:
2012-06-07 @ 13:10
Le 07/06/2012 12:34, Alex K a écrit :
> Then I go to url '/statistic/test' and it not work (404 not found).
>
> But in '/test' it work.

You’re using this:

app.add_url_rule('/test', ...)


Try this instead:

some_blueprint.add_url_rule('/test', ...)
# only after that:
app.register_blueprint(some_blueprint, ...)


Regards,
-- 
Simon Sapin

Re: [flask] MethodView and url_prefix for blueprint

From:
Alex K
Date:
2012-06-07 @ 13:40
Thanks, it works :)


On Thu, Jun 7, 2012 at 5:10 PM, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 07/06/2012 12:34, Alex K a écrit :
> > Then I go to url '/statistic/test' and it not work (404 not found).
> >
> > But in '/test' it work.
>
> You’re using this:
>
> app.add_url_rule('/test', ...)
>
>
> Try this instead:
>
> some_blueprint.add_url_rule('/test', ...)
> # only after that:
> app.register_blueprint(some_blueprint, ...)
>
>
> Regards,
> --
> Simon Sapin
>
>
>