I'm trying to update my webapp2 router to take me to a different handler in a certain case here is what I have:
address: "*.com/blog/post?action=edit&id=fl2j3r0udflj3"
to keep it simple I want to just match on /blog/post?action=edit
I have this:
app = webapp2.WSGIApplication([
('/',Redirect),
(r'/blog/post?(\S+)', blog.EditPost),
('/blog/post', NewPost),
....
doesn't work.
I've tried several different things such as
Nothing is working. Any ideas?
tl;dr: If you want to maintain your URL structure, your '/blog/post' handler is going to need to dispatch further based on presence parameters and their values.
This is one of those situations were it helps to have prior knowledge of what's meant by a 'path' when talking about URLs. Specifically, that parameters aren't part of the path.
It's also solvable by digging in to the SDK source, with the goal of answering the question "which part of the URL is being considered when matching routes?"
webapp2
provides functionality on top of webob
. webapp2.WSGIApplication
builds a list of webapp2.SimpleRoute
s for the routes passed to the WSGIApplication
constructor. A SimpleRoute
"matches" based on request.path
, which is a property on the request provided by webob.Request
(which webapp2.Request
subclasses). The path
property starts with
@property
def path(self):
"""The path of the request, without host or query string"""
Meaning, ultimately, that query strings aren't matchable by routes. (You could dig further in to code to confirm that.)