urls: /myview -> /myview/

5 views
Skip to first unread message

Benoit Chesneau

unread,
Dec 4, 2007, 7:43:43 PM12/4/07
to web.py
Hi,

How can I have url ending with or without '/' going to the same
Class ? Is there a "simple" way ?

Btw why if Import myapp and put myapp.views.MyClass in the urls it
doesn't work ? I have to do "from myapp.views import MyClass" and then
put MyClass in urls to have it working. Any idee ?

Maybe because I use globals() but how to replace it ?


many questions for know, juste started to play with webpy ;)


- benoît

bubblboy

unread,
Dec 4, 2007, 8:09:11 PM12/4/07
to we...@googlegroups.com
Benoit Chesneau wrote:
> Hi,
>
> How can I have url ending with or without '/' going to the same
> Class ? Is there a "simple" way ?

I'm only going to answer this one because it's easy: regular
expressions. Before I elaborate, though, a word of advice: this is /not/
a good idea. Not as you formulate it, at least. Do not make them point
to the same class; make them /redirect/ to the right class. This way
there will be no two pages with exactly the same content on your website
(this confuses bots and many other tools; for example, a browser will
not remember going to the page without a / so will not colour it
purple-or-whatever, which might confuse the visitor; "huh, didn't I
already go there?" etcetera etcetera). No, I am not making this up:
google will kill you if you do so (it is not considered a good thing if
you have bogus content, and duplicate content is bogus in their eyes).
If not google then other search engines.

Anyway.

Make a regexp that grabs any page without trailing slash, optionally
checks if there is an entry with slash defined in the urls list and
redirects the user (301).

> Btw why if Import myapp and put myapp.views.MyClass in the urls it
> doesn't work ? I have to do "from myapp.views import MyClass" and then
> put MyClass in urls to have it working. Any idee ?
>
> Maybe because I use globals() but how to replace it ?
>
>
> many questions for know, juste started to play with webpy ;)
>
>
> - benoît

Hope this answers your question.

b^4

Anand Chitipothu

unread,
Dec 4, 2007, 8:21:24 PM12/4/07
to we...@googlegroups.com
On Dec 5, 2007 6:13 AM, Benoit Chesneau <bche...@gmail.com> wrote:
>
> Hi,
>
> How can I have url ending with or without '/' going to the same
> Class ? Is there a "simple" way ?

add the following to the beginning of urls.

"/(.*)/", "redirect",

and have the following class to handle those urls.

class redirect:
def GET(self, path):
web.seeother('/' + path)

Benoit Chesneau

unread,
Dec 7, 2007, 9:26:31 AM12/7/07
to web.py


On Dec 5, 2:21 am, "Anand Chitipothu" <anandol...@gmail.com> wrote:
> add the following to the beginning of urls.
>
> "/(.*)/", "redirect",
>
> and have the following class to handle those urls.
>
> class redirect:
> def GET(self, path):
> web.seeother('/' + path)
thanks will test it. I have a look on the way use in infogammi too.
It's interresting.
Reply all
Reply to author
Forward
0 new messages