1

When I control different type of pages, I move my code to another python file. But this way has disadvantage : each time I want to change url hander, I must comback to main.py to config bottom lines about url handler. for example :

app = webapp2.WSGIApplication([('/', MainPage),
                               ('/thanks',ThanksHandler),
                               ('/unit2/signup',Signup),
                               ('/unit2/successful', LoginSuccess)], debug=True)

I try to config handler in app.yaml to prevent dis advantage.

I add file blog.py in same directory and in this file, I have Blog class. And here is my blog.py file:

class Blog(BaseHandler):
    def get(self):
        self.response.out.write("Hello")

app = webapp2.WSGIApplication([('/blog', Blog)], debug=True)

Here is original file:

> handlers:
> - url: /favicon\.ico   static_files: favicon.ico   upload: favicon\.ico

- url: /.*   script: main.app

and this new file app.yaml:

handlers:
- url: /favicon\.ico   static_files: favicon.ico   upload: favicon\.ico

- url: /blog/.*   script: blog.app

- url: /.*   script: main.app

But when I goto: localhost:port/blog : 404: resource not found.

Please help me.

Thanks :)

2
  • Put your /.* handler last; that matches everything. Commented Jul 6, 2012 at 18:59
  • @Wooble after I change, i still see resource not found. Can you look at : url: /blog/.* script: blog.app, does this url handler true for link localhost/blog ? Commented Jul 6, 2012 at 19:03

1 Answer 1

3

The /blog/.* url specification from the yaml file does not match the url specification from the blog.py file (/blog). In particular the fact that /blog/.* requires the url to have a slash after blog. If for example you use just /blog in both places it will work. Or you can use /blog/.* in both places.

The url specifiers are matched in the order in which they appear in the yaml file therefore in this particular case /blog/.* will not match on /blog but will match on the last (catch all really) /.* specifier and therefore main.py handler will be loaded and fail to match (no pattern in the call WSGIApplication constructor inside main.py).

Hope this helps. -Silviu

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.