Bhushan Bhushan - 1 month ago 13
Python Question

Google App Engine displays nothing

I am trying to take data from user and store it in database but even my form isn't displaying on chrome. I am new to google app engine please help. Following is my complete code

import webapp2
from google.appengine.ext import db

class Dealer(db.Model):
dealer_name = db.StringProperty(required = True)
dealer_phone = db.StringProperty(required = True)

class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write("""
<form action="store_dealer" method="post">
<input type="text" name="dealer_name">
<input type="text" name="dealer_phone">
<input type="submit"/>
</form>
""")

class StoreDealer(webapp2.RequestHandler):
def post(self):
dealer_name=self.request.get('dealer_name')
dealer_phone=self.request.get('dealer_phone')
if dealer_name && dealer_phone:
dealer = Dealer(dealer_name = dealer_name, dealer_phone = dealer_phone)
dealer.put()
self.redirect('/')

app = webapp2.WSGIApplication([
('/', MainHandler),
('/store_dealer',StoreDealer)
], debug=True)

Answer

The equivalent of && is and in Python.

So your code should be like this.

class StoreDealer(webapp2.RequestHandler):
    def post(self):
        ..........
        if dealer_name and dealer_phone:
            ...........

To view the errors on Google App Engine, Please check its log console.

Comments