2013-10-12 100 views
2

我在應用程序中創建了一個實體「FlipKart」,並使用了一個處理程序,我已經運行了一個查詢,以便可以在我的HTML表單中顯示給定條目。我有用於組織我的html文件的Jinja2模板。未顯示Google App Engine數據庫

下面是實體代碼:

class FlipKart(db.Model): 
    name = db.StringProperty()    
    quantity = db.IntegerProperty() 
    total = db.IntegerProperty()  

這裏就是我處理和運行我的查詢處理程序:

class WebeHandler(Handler):   
    def get(self): 
     self.render("we.html") 
    def post(self): 
     b_name = self.request.get("bkname") 
     b_quantity = self.request.get("qnty") 
     b_total = self.request.get("tot")   

     if(b_name and b_quantity and b_total): 
      a = FlipKart(BookName = b_name, Quantity = b_quantity, GrandTotal = b_total) 
      a.put() 
      self.final() 
    def final(self): 
     flips = db.GqlQuery("SELECT * FROM FlipKart") 
     self.render("we.html", flips = flips) 

這裏是我的html文件:

<html> 
<head> 
    <title>Web Engineering</title> 
    <style type = "text/css"> 

    </style> 
</head> 

<body> 
    <form method = "post"> 
     Book Name<input type = "text" name = "bkname"> 
     <br> 
     Quantity<input type = "text" name = "qnty"> 
     <br> 
     Total Prize<input type = "number" name = "tot"> 
     <br> 
     <input type = "submit"> 
     <br><br><br> 
     <hr> 

     {% 
      for flip in flips 
     %} 
      <div>You have ordered a {{flip.name}}</div> 
     {%endfor%} 
    </form> 
</body> 

然而,whe n我運行這個應用程序,在瀏覽器中獲得以下文本:

You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 
You have ordered a None 

什麼似乎是問題?

回答

5

你的查詢沒有問題,你可以看到循環重複。 你的問題是你創建的實體

a = FlipKart(BookName = b_name, Quantity = b_quantity, GrandTotal = b_total)

的地方作爲

class FlipKart(db.Model): 
    name = db.StringProperty()    
    quantity = db.IntegerProperty() 
    total = db.IntegerProperty() 

你實際上並沒有存儲任何的實體值的模型定義代碼。這是非常基本的python。

類構造函數調用應該是

a = FlipKart(name = b_name, quantity = b_quantity, total = b_total)

你需要做的INT轉換以及每個對方的回答,你不分配得到一個錯誤的唯一原因是你在哪裏從未分配屬性的值。

另外請注意您的查詢可能不會顯示由於最終相合最近添加的實體,(我會讓你做一些閱讀上)