Reputation: 1467
I am a GAE and Python newbie. I am not able to pass a string parameter from my HTML page to a Python function (it works for integer parameters though).
I have the following URL:
http://localhost:8094/papers/xyz
In main()
I have:
app = webapp2.WSGIApplication([
('/', homepage.ViewHomePage),
('/about', aboutpage.ViewAboutPage),
('/papers/([\w]+)', PaperList)
],
config=config,
debug=True)
The function is defined as:
class PaperList(BaseHandler):
def get(self, param1):
In app.yaml
I have:
- url: .*
script: main.app
This does not work. However, if I just change the parameter from a string to an integer, then it works. (I am not doing anything with the parameter yet, just want it to accept the string parameter.)
Can someone tell me what I have to change to allow it to work with a string parameter and also point me to where the documentation explains how to pass parameters through main()
?
I am using Python 2.7.
Upvotes: 0
Views: 1286
Reputation: 247
you also have the option of passing urlencoded data such as yourapp.appspot.com/papers?keyword=helloworld
and get it in your handler with: keyword = self.request.GET.get('keyword') or keyword = self.request.POST.get('keyword') depending on your request method.
you can also pass json data in the body of a AJAX post and use json to deserialize it into python data. To validate this kind of data, I recommend voluptuous.
Upvotes: 0
Reputation: 799310
\d
only matches decimal digits. Did you mean to use \w
instead? Also, no square brackets.
Upvotes: 2