Reputation: 2835
I'm writing a simple "Hello world" with apache and web.py. The app works when I go to
http://sandbox-dev.com/webapp/
but not when I go to:
http://sandbox-dev.com/webapp
My intuition (clearly wrong) was that the following code would have matched either of these addresses.
import sys, os
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)
import web
urls = (
'/.*', 'hello',
)
class hello:
def GET(self):
return "Hello, web.py world."
application = web.application(urls, globals()).wsgifunc()
What do I need to change in order to match both of these?
Upvotes: 1
Views: 799
Reputation: 257
@Anand Chitipothu is right.
http://sandbox-dev.com/webapp/ matches '/'
and
http://sandbox-dev.com/webapp matches '' #empty string
so if you want to fix it in webpy, you can write:
urls = (
'.*', 'hello' #match all path including empty string
)
or add a Redirect class
urls = (
'/.*', 'hello',
'', 'Redirect'
)
class Redirect(object):
def GET(self):
raise web.seeother('/') # this will make the browser jump to url: http://sandbox-dev.com/webapp/
Upvotes: 0
Reputation: 4357
When the URL is "http://sandbox-dev.com/webapp", web.py sees it as "", not as "/". So changing the url pattern to ".*" will work.
But, probably you should fix that in your apache configuration and not in webapp. Add a rule to redirect /webapp to /webapp/.
Upvotes: 3
Reputation: 18850
If you're trying to have the front page be handled by the class hello, all you need is this:
urls = (
'/', 'hello',
)
Or did I misunderstand your intentions?
Upvotes: 0