this is simple code to test the redirection in html.and I use Spyder to write Python Code.
import webapp2
from valid_day import valid_day
from valid_month import valid_month
from valid_year import valid_year
from html_escape import escape_html
form = """
<form method="post">
What is your birthday?
<br>
<label>
Month
<input type="text" name="month" value="%(month)s">
</label>
<label>
Day
<input type="text" name="day" value="%(day)s">
</label>
<label>
Year
<input type="text" name="year" value="%(year)s">
</label>
<div style="color: red">%(error)s</div>
<br><br>
<input type="submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
def write_form(self, error="", month="", day="", year=""):
self.response.out.write(form %{"error": error,
"month": escape_html(month),
"day": escape_html(day),
"year": escape_html(year)})
def get(self):
self.write_form()
def post(self):
user_month = self.request.get('month')
user_day = self.request.get('day')
user_year = self.request.get('year')
month = valid_month(user_month)
day = valid_day(user_day)
year = valid_year(user_year)
if not(month and day and year):
self.write_form("That doesn't look valid to me, friend.", user_month, user_day, user_year)
else:
self.redirect("/thanks")
class ThanksHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write("Thanks! That's a totally valid day!")
app = webapp2.WSGIApplication([('/', MainPage),
('/thanks', ThanksHandler)],
debug=True)
while the code worked well with GAE and on my http://localhost:8081/, it failed when I try to run the Code through a click in Spyder.the error message is: ImportError: No module named webapp2 I've also read import webapp2 works on google-app-engine even though I don't have webapp2 installed and add GAE directory to my ~/.bashrc as fellow:
export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/"
export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/lib/"
export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/lib/yaml"
but this also doesn't work even if i restarted the ubuntu.
The GAE app code is not intended to be executed directly, as a standalone app, it needs to be executed by the development server which knows how to load and execute the app code (while complementing it with the emulated GAE python sandbox functionality). See Using the Local Development Server.
You might be able to execute it together with the SDK (i.e. execute
dev_appserver.py
and pass it the same args as when you did when you got it working without spyder). But I'm not familiar with Spyder, I'm unsure if it supports such execution of your app code through a 3rd party tool (and if it does - if it really is practical/useful for development)