clifgray
clifgray

Reputation: 4419

python url mapping syntax

I am writing a python program for google appengine using jinja2 as my template engine. I would like to have a single handler for a multitude of posts and some of them having pretty different URLs but all having the same base.

Is is possible for me to have a URL handler like this:

app = webapp2.WSGIApplication([('/post/([.*]+)/([.*]+)/([.*]+)/([.*]+)', PostPage), ], debug=True)

And yet have it accept URLs that don't fill every one of those addtitions like having a URL:

/post/1234/some-title

If not is there some way that I can change it so that one handler can take URLs for many pages?

Upvotes: 2

Views: 502

Answers (1)

Shay Erlichmen
Shay Erlichmen

Reputation: 31928

If you don't need (as parameters for the handler) the parts of the path that are after the /post/{param1} you can simple write app = webapp2.WSGIApplication([('/post/(.*)/.*', PostPage) and the handler will except everything in the form of /post/{id}/.*

Upvotes: 3

Related Questions