librelist archives

« back to archive

Why url_for with dot work and without it doesn't

Why url_for with dot work and without it doesn't

From:
Jose Ayerdis
Date:
2013-01-28 @ 20:34
Hello flask folks, I ran into the case of trying to get url_for but my
endpoint was with MethodView, I saw a post a year ago with a similar case
and a commit was made to fix this adding the _method parameter wich you can
use to specify *HTTP Verb.*

Nevertheless I encounter that inside a blueprint that I configure my
MethodViews classes I use

*Does not work:*

print url_for('myService',uid=result.uid,_method='GET')

*This work*

print url_for('.myService',uid=result.uid,_method='GET')


Just want to know what is the difference between one and the other ?
(beside the obvious dot at the begining :D).


Thanks

Sincerly yours,

[Jose Luis Ayerdis Espinoza]
Necronet.info |
LinkedIn<http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704>|
Careers
StackOverflow <http://careers.stackoverflow.com/necronet>

Re: [flask] Why url_for with dot work and without it doesn't

From:
Simon Sapin
Date:
2013-01-29 @ 16:32
Le 28/01/2013 21:34, Jose Ayerdis a écrit :
> Hello flask folks, I ran into the case of trying to get url_for but my
> endpoint was with MethodView, I saw a post a year ago with a similar
> case and a commit was made to fix this adding the _method parameter wich
> you can use to specify *HTTP Verb.*
>
> Nevertheless I encounter that inside a blueprint that I configure my
> MethodViews classes I use
>
> *Does not work:*
>
> print url_for('myService',uid=result.uid,_method='GET')
>
> *This work*
>
> print url_for('.myService',uid=result.uid,_method='GET')
>
>
> Just want to know what is the difference between one and the other ?
> (beside the obvious dot at the begining :D).

Hi,

The string you pass to url_for() is a *endpoint*.

When adding routes directly on a Flask app (without blueprints), the 
endpoint defaults to the function’s name. With blueprints, the endpoint 
is '<blueprint name>.<function name>'

Since copying the blueprint name all the time is boring, url_for() 
accepts '.<name>' as short for '<name of the current blueprint>.<name>'

Of course only works when calling url_for() in a request context for a 
request in a blueprint, otherwise there is no "current blueprint".

http://flask.pocoo.org/docs/blueprints/#building-urls
http://flask.pocoo.org/docs/api/#flask.url_for

Cheers,
-- 
Simon Sapin

Re: [flask] Why url_for with dot work and without it doesn't

From:
Trey Long
Date:
2013-01-29 @ 01:27
Well, I don't know much about _method but I think it's just to append a 
special query string to the URL for a middleware to interpret for you when
it's sent back into your system. I shouldn't matter if you aren't using 
that. It especially doesn't matter if you're using 'GET' because that's 
always the default.

The difference between the non dot and dot version are blueprints. It 
seems to me like you have a myService in your blueprint but not in the app
itself. So referencing it with the '.' would be correct.

I'm not an expert on either of these topics though, so it's also possible 
I have no clue what I'm saying.


On Jan 28, 2013, at 3:34 PM, Jose Ayerdis <joseayerdis@gmail.com> wrote:

> Hello flask folks, I ran into the case of trying to get url_for but my 
endpoint was with MethodView, I saw a post a year ago with a similar case 
and a commit was made to fix this adding the _method parameter wich you 
can use to specify HTTP Verb.
> 
> Nevertheless I encounter that inside a blueprint that I configure my 
MethodViews classes I use
> 
> Does not work:
> 
> print url_for('myService',uid=result.uid,_method='GET')
> 
> This work
> 
> print url_for('.myService',uid=result.uid,_method='GET')
> 
> 
> Just want to know what is the difference between one and the other ? 
(beside the obvious dot at the begining :D).
> 
> 
> Thanks
> 
> Sincerly yours,
> 
> [Jose Luis Ayerdis Espinoza]
> Necronet.info | LinkedIn | Careers StackOverflow

Re: [flask] Why url_for with dot work and without it doesn't

From:
Jose Ayerdis
Date:
2013-01-29 @ 15:11
The blueprint explanation make sense since  I am inside one. I think that
the method GET does matter though specially if you are using MethodView.

Sincerly yours,

[Jose Luis Ayerdis Espinoza]
Necronet.info |
LinkedIn<http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704>|
Careers
StackOverflow <http://careers.stackoverflow.com/necronet>


2013/1/29 Trey Long <trey@ktrl.com>

> Well, I don't know much about _method but I think it's just to append a
> special query string to the URL for a middleware to interpret for you when
> it's sent back into your system. I shouldn't matter if you aren't using
> that. It especially doesn't matter if you're using 'GET' because that's
> always the default.
>
> The difference between the non dot and dot version are blueprints. It
> seems to me like you have a myService in your blueprint but not in the app
> itself. So referencing it with the '.' would be correct.
>
> I'm not an expert on either of these topics though, so it's also possible
> I have no clue what I'm saying.
>
>
> On Jan 28, 2013, at 3:34 PM, Jose Ayerdis <joseaye 
rdis@gmail.com<joseayerdis@gmail.com>>
> wrote:
>
> Hello flask folks, I ran into the case of trying to get url_for but my
> endpoint was with MethodView, I saw a post a year ago with a similar case
> and a commit was made to fix this adding the _method parameter wich you can
> use to specify *HTTP Verb.*
>
> Nevertheless I encounter that inside a blueprint that I configure my
> MethodViews classes I use
>
> *Does not work:*
>
> print url_for('myService',uid=result.uid,_method='GET')
>
> *This work*
>
> print url_for('.myService',uid=result.uid,_method='GET')
>
>
> Just want to know what is the difference between one and the other ?
> (beside the obvious dot at the begining :D).
>
>
> Thanks
>
> Sincerly yours,
>
> [Jose Luis Ayerdis Espinoza]
> Necronet.info <http://necronet.info/> | 
LinkedIn<http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704>|
Careers
> StackOverflow <http://careers.stackoverflow.com/necronet>
>
>
>

Re: [flask] Why url_for with dot work and without it doesn't

From:
Trey Long
Date:
2013-01-29 @ 15:40
Does the output of the function actually change if you have _method='GET' or not?

On Jan 29, 2013, at 10:11 AM, Jose Ayerdis <joseayerdis@gmail.com> wrote:

> The blueprint explanation make sense since  I am inside one. I think 
that the method GET does matter though specially if you are using 
MethodView.
> 
> Sincerly yours,
> 
> [Jose Luis Ayerdis Espinoza]
> Necronet.info | LinkedIn | Careers StackOverflow
> 
> 
> 2013/1/29 Trey Long <trey@ktrl.com>
> Well, I don't know much about _method but I think it's just to append a 
special query string to the URL for a middleware to interpret for you when
it's sent back into your system. I shouldn't matter if you aren't using 
that. It especially doesn't matter if you're using 'GET' because that's 
always the default.
> 
> The difference between the non dot and dot version are blueprints. It 
seems to me like you have a myService in your blueprint but not in the app
itself. So referencing it with the '.' would be correct.
> 
> I'm not an expert on either of these topics though, so it's also 
possible I have no clue what I'm saying.
> 
> 
> On Jan 28, 2013, at 3:34 PM, Jose Ayerdis <joseaye rdis@gmail.com> wrote:
> 
>> Hello flask folks, I ran into the case of trying to get url_for but my 
endpoint was with MethodView, I saw a post a year ago with a similar case 
and a commit was made to fix this adding the _method parameter wich you 
can use to specify HTTP Verb.
>> 
>> Nevertheless I encounter that inside a blueprint that I configure my 
MethodViews classes I use
>> 
>> Does not work:
>> 
>> print url_for('myService',uid=result.uid,_method='GET')
>> 
>> This work
>> 
>> print url_for('.myService',uid=result.uid,_method='GET')
>> 
>> 
>> Just want to know what is the difference between one and the other ? 
(beside the obvious dot at the begining :D).
>> 
>> 
>> Thanks
>> 
>> Sincerly yours,
>> 
>> [Jose Luis Ayerdis Espinoza]
>> Necronet.info | LinkedIn | Careers StackOverflow
> 
>