这是我的main.py,我想在等号后提取所有内容。
示例网址将是
/loggedin?frob=72157645687641769-37c9ec9b8fb35d48-125787757
我想提取72157645687641769-37c9ec9b8fb35d48-125787757
import webapp2
from flickr.views import Flickr, FlickrAuthorized
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/', MainHandler),
('/index', Flickr),
(r'/loggedin?frob=<:((?:[a-z][a-z]*[0-9]+[a-z0-9]*))>', FlickrAuthorized)
], debug=True)
我的处理程序有以下类:
class FlickrAuthorized(webapp2.RequestHandler):
def get(self, frob):
print frob
//code
答案 0 :(得分:5)
您应该从处理程序中访问查询字符串部分,而不是在URL中匹配它们:
class FlickrAuthorized(webapp2.RequestHandler):
def get(self):
frob = self.request.get('frob')
# code...
app = webapp2.WSGIApplication([
('/', MainHandler),
('/index', Flickr),
(r'/loggedin', FlickrAuthorized)
], debug=True)