crud.create(db...,next="...[id]") error

46 views
Skip to first unread message

szimszon

unread,
Sep 19, 2009, 2:46:32 PM9/19/09
to web2py-users
Hi All!

I wonder if somebody could help me.

I have:

form=crud.create(db.oklevel_sablon,next=URL
(r=request,f='sablonsor_jog',args="[id]"))

But the next url looks:
.../sablonsor_jog/%5Bid%5D

The "[id]" isn't replaced with the created record's number :(

I read in the book page 217:

"• next is the URL to redirect to after success. If the URL
contains the
substring "[id]" this will be replaced by the id of the record
currently
created/updated."

Yarko Tymciurak

unread,
Sep 19, 2009, 3:00:02 PM9/19/09
to web...@googlegroups.com
On Sat, Sep 19, 2009 at 1:46 PM, szimszon <szim...@gmail.com> wrote:

Hi All!

I wonder if somebody could help me.

I have:

form=crud.create(db.oklevel_sablon,next=URL
(r=request,f='sablonsor_jog',args="[id]"))

But the next url looks:
.../sablonsor_jog/%5Bid%5D

The "[id]" isn't replaced with the created record's number :(

I think you misread this:   it says:

"""
* next is the URL to redirect to after success.  If the URL [NOTE: NOT the CALL to the helper function URL(), but the string of the target URL itself!]  contains the substring "[id]" this will be replaced by the id of the record currently created/updated
"""

Is this enough of a hint, or do you need an example?
(Suggestion:  put the output from the URL() call in a variable, don't specify "args" in the URL() call, rather catenate "[id]" to what URL() gives you)

szimszon

unread,
Sep 20, 2009, 4:28:33 AM9/20/09
to web2py-users
I'm a bit puzzled :(

I modified the code:

n=str(URL(r=request,f='sablonsor_jog')+'/[id]')
sablon_sor=crud.create(db.oklevel_sablon,next=n)

but it's not working. Type of 'n' is 'str'.

And the

n='/borverseny/adatok/sablonsor_jog'+'/[id]'

doesn't work either.

But

n='borverseny/adatok/sablonsor_jog'+'/[id]'

works. So I think the point is that if the url string begins with the
'/' then the replace doesn't work. If the url begins not with '/' than
everything is working right.
On szept. 19, 21:00, Yarko Tymciurak <yark...@gmail.com> wrote:

Iceberg

unread,
Sep 20, 2009, 5:09:14 AM9/20/09
to web2py-users
On Sep20, 4:28pm, szimszon <szims...@gmail.com> wrote:
> I'm a bit puzzled :(
>
> I modified the code:
>
> n=str(URL(r=request,f='sablonsor_jog')+'/[id]')
> sablon_sor=crud.create(db.oklevel_sablon,next=n)
>
> but it's not working. Type of 'n' is 'str'.
>
> And the
>
> n='/borverseny/adatok/sablonsor_jog'+'/[id]'
>
> doesn't work either.
>
> But
>
> n='borverseny/adatok/sablonsor_jog'+'/[id]'
>
> works. So I think the point is that if the url string begins with the
> '/' then the replace doesn't work. If the url begins not with '/' than
> everything is working right.


Yeah, I met same problem before. It is all because web2py's gluon/
tools.py does the "[id]" magic ONLY for a url NOT begins with the '/'.
The source code has many snippets like this.

if next and not next[0] == '/' and next[:4] != 'http':
next = self.url(next.replace('[id]', str
(form.vars.id)))

I don't know the reason for requiring a leading '/'. Perhaps Massimo
will tell us more.

Sincerely,
Iceberg

Yarko Tymciurak

unread,
Sep 21, 2009, 12:20:46 PM9/21/09
to web...@googlegroups.com
sounds like this needs to be straightened out;  probably deserves some discussion (as Iceberg suggests)...

Massimo - can you add your thoughts to this?

mdipierro

unread,
Sep 21, 2009, 5:08:30 PM9/21/09
to web2py-users
because in web2py request.args are optional I think it is dangerous to
have relative URLs that do not start with '/'.
web2py assumes that if a url does not start with '/' that is an
extenal URL (starts with http:, ftp: etc.)

On Sep 21, 11:20 am, Yarko Tymciurak <yark...@gmail.com> wrote:
> sounds like this needs to be straightened out;  probably deserves some
> discussion (as Iceberg suggests)...
>
> Massimo - can you add your thoughts to this?
>

Yarko Tymciurak

unread,
Sep 21, 2009, 6:43:22 PM9/21/09
to web...@googlegroups.com
then perhaps crud.*   next=.... [id]  behavior should be reviewed?

mdipierro

unread,
Sep 21, 2009, 9:12:46 PM9/21/09
to web2py-users
what do you propose?

On Sep 21, 5:43 pm, Yarko Tymciurak <yark...@gmail.com> wrote:
> then perhaps crud.*   next=.... [id]  behavior should be reviewed?
>

Iceberg

unread,
Sep 22, 2009, 12:30:42 PM9/22/09
to web2py-users
Sorry, still don't get the point. In my understanding:
1. URLs that starts with http: or ftp: etc are certainly external URL.
2. URLs that starts with / are absolute path of current host
3. URLs other than above are relative path of current host
so which one do you consider dangerous and could you please give an
example?

Yarko Tymciurak

unread,
Sep 23, 2009, 12:32:32 PM9/23/09
to web...@googlegroups.com
and the point here:  currently, the way code is written,  [id] in a URL will be replaced by the created/modified id or the record EXCEPT if it is relative, or absolute (e.g. ONLY  '/' leading URL paths will have [id] set, as shown in the manual).

The question of "what is safe; what isn't"   isn't the primary issue here - it is the behavior (advertised/expected;   actual;  what is really desired) for this "[id]" replacement.

Let's get to that first, shall we?

THEN we can discuss the various path contexts....

szimszon

unread,
Sep 23, 2009, 2:53:08 PM9/23/09
to web2py-users
Okay :)

I'm not particular good in English but in:

"• next is the URL to redirect to after success. If the URL
contains the
substring "[id]" this will be replaced by the id of the record
currently
created/updated."

is nowhere that the URL must not contain '/' in the first place.

This is from the book 2nd edition page 217...

On szept. 23, 18:32, Yarko Tymciurak <yark...@gmail.com> wrote:
> and the point here:  currently, the way code is written,  [id] in a URL will
> be replaced by the created/modified id or the record EXCEPT if it is
> relative, or absolute (e.g. ONLY  '/' leading URL paths will have [id] set,
> as shown in the manual).
>
> The question of "what is safe; what isn't"   isn't the primary issue here -
> it is the behavior (advertised/expected;   actual;  what is really desired)
> for this "[id]" replacement.
>
> Let's get to that first, shall we?
>
> THEN we can discuss the various path contexts....
>

Yarko Tymciurak

unread,
Sep 23, 2009, 3:01:35 PM9/23/09
to web...@googlegroups.com
On Wed, Sep 23, 2009 at 1:53 PM, szimszon <szim...@gmail.com> wrote:

Okay :)

I'm not particular good in English but in:

"• next     is the URL to redirect to after success. If the URL
contains the
 substring "[id]" this will be replaced by the id of the record
currently
 created/updated."

is nowhere that the URL must not contain '/' in the first place.

... thanks for the correction ... also, must not be absolute path...

 

Iceberg

unread,
Sep 24, 2009, 2:21:36 AM9/24/09
to web2py-users
I don't really care which question is the primary one but, it doesn't
harm to go back to the beginning point: Currently, the way code is
written, [id] in a URL will
be replaced by the created/modified id of the record, ONLY IF it is
relative path (No leading '/', no leading 'http:'). The side effect is
that, one obvious usage:
next=URL(...)
doesn't work, which is not desired IMHO.

szimszon

unread,
Sep 24, 2009, 3:25:31 AM9/24/09
to web2py-users
From my point of view I don't care. I just pointed out that the
documentation isn't exact and not only the
next=URL(...)
doesn't working but
next='/some/path/[id]'
too.

Anyway great software! Tnx Massimo!

Yarko Tymciurak

unread,
Sep 24, 2009, 8:05:26 PM9/24/09
to web...@googlegroups.com
On Thu, Sep 24, 2009 at 1:21 AM, Iceberg <ice...@21cn.com> wrote:

I don't really care which question is the primary one but, it doesn't
harm to go back to the beginning point: Currently,  the way code is
written,  [id] in a URL will
 be replaced by the created/modified id of the record, ONLY IF it is
relative path (No leading '/', no leading 'http:'). The side effect is
that, one obvious usage:
 next=URL(...)
doesn't work, which is not desired IMHO.

Yes, precisely - and I agree (that URL() calls should work with this 'feature') - this is what needs discussion, and Massimo's agreement (or alternate position at least).

- Yarko

Reply all
Reply to author
Forward
0 new messages