custom URI dont work!

100 views
Skip to first unread message

aliane abdelouahab

unread,
Oct 7, 2012, 5:14:37 PM10/7/12
to Tornado Web Server
i've a variable and i try to make an url based from this variable
(like the one in facebook):
the variable is produit["spec"]["id"] and gives the value for example:
alucaard134962088117
so i want and url like : localhost:8000/alucaard134962088117

first i made this:

<span class="site"><a href="{{produit["spec"]["id"]}}">Page du
Produit</a></span>

then it dident work, then i changed it to:

<span class="site">
<form action="/{{produit["spec"]["date"]}}">
<input type="hidden" value="{{produit["spec"]["date"]}}" name="url" /
>
<input type="submit" value="Page du produit" />
</form>

the url spec:

(r"/*([a-zA-Z0-9]+)*", handlers.Produit),

and to make the test, i've made this to see if the class is reached:

class Produit(BaseHandler):
def get(self):
print "hello"

but i get the error:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 1064, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 1846, in wrapper
return method(self, *args, **kwargs)
TypeError: get() takes exactly 1 argument (2 given)

there is the easier way to make a single uri for all product since
it's only the variable that is changing, but why this dont work?

Lysander Trischler

unread,
Oct 8, 2012, 2:42:46 PM10/8/12
to python-...@googlegroups.com
Hi,

> […] then it dident work […]

first of all, a single "this does not work" is absolutely useless. Nobody will
or even *can* help you without any information.

Indeed this article addresses bug reports but applys for generic problems like
this one as well: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

You're posts slightly getting better but often still lack important
information so please try to provide more of them in the first place in the
future.

> TypeError: get() takes exactly 1 argument (2 given)

As you can clearly see from the exception's message, your get method in the
Produit class (as far as routing works properly) is called with two arguments
instead of one parameter. This second one comes from your regular expression
of the URL. The URLSpec documentation¹ says:

| […] Any groups in the regex will be passed in to the handler's get/post/etc
| methods as arguments […]

So either remove the parentheses from the regex (this is *not* what you want)
or let the get method also have a product ID parameter (take this approach):

class Produit(BaseHandler):
def get(self, product_id):
// ... do sth. with the product_id

Regards,
Lyse

¹: http://www.tornadoweb.org/documentation/web.html#tornado.web.URLSpec

aliane abdelouahab

unread,
Oct 8, 2012, 5:55:07 PM10/8/12
to Tornado Web Server
thank you for the reply :)
but, why it's not like in the other GET, POST, i use them without
using a second parameter than Self ? is it a special case because
there is a regular expression in the action done in the form?

aliane abdelouahab

unread,
Oct 8, 2012, 6:05:02 PM10/8/12
to Tornado Web Server
and sorry if i report bad my error :p
still learning ;)

On 8 oct, 19:42, Lysander Trischler <goo...@lyse.isobeef.org> wrote:

Lysander Trischler

unread,
Oct 9, 2012, 1:17:37 PM10/9/12
to python-...@googlegroups.com
Hi,

> but, why it's not like in the other GET, POST, i use them without
> using a second parameter than Self ? is it a special case because
> there is a regular expression in the action done in the form?

no, most likely because in the old days you put the ID into the URL query not
path segment¹ as now. See the regex syntax for groups².

Regards,
Lyse

¹: http://en.wikipedia.org/wiki/Uniform_resource_locator#Syntax
²: http://docs.python.org/library/re.html#regular-expression-syntax

aliane abdelouahab

unread,
Oct 9, 2012, 6:20:02 PM10/9/12
to Tornado Web Server
ah, now i get more information!
thank you :D
i'll test the application and give you the feedback tomorrow (because
i'm in a cyber cafe)

aliane abdelouahab

unread,
Oct 15, 2012, 11:41:11 AM10/15/12
to Tornado Web Server
i still dont get how to pass a variable to put it in the uri?

On 9 oct, 18:17, Lysander Trischler <goo...@lyse.isobeef.org> wrote:

aliane abdelouahab

unread,
Oct 15, 2012, 5:32:44 PM10/15/12
to Tornado Web Server
am sorry, finally it worked:
it seems that i must pass the variable using a hidden form and then
call it with GET(self, the variable) and in url i put this: (r"/
info*([a-zA-Z0-9]+)*", handlers.Produit) to get something like that:
http://localhost:8000/info?id=alucaard134962088117

i hear about reverse_url(name, *args) but how to use it?
Reply all
Reply to author
Forward
0 new messages