0
私はpythonとWebプログラミングに新しいです。私は、ユーザーがテキストボックスに入力した内容に基づいてクエリー結果を返し、次にsubmitをヒットする、jinja2とwebapp2ライブラリを使用して、アプリケーションエンジンにいくつかの動作するhtmlとpythonコードを持っています。テキストボックスが更新され、送信ボタンが必要ないときはいつでもPOSTコードが実行されるようにコードを変更したいと思います。これを達成するためのコードサンプルやガイダンスは高く評価されます。テキストフィールドへの更新を提出する - python
class MainPage(webapp2.RequestHandler):
def get(self):
template = JINJA_ENVIRONMENT.get_template('index.html')
textInput = ""
products = ""
queryTime = 0
template_values = {
'products': products,
'textInput': textInput,
'queryTime': queryTime,
}
self.response.write(template.render(template_values))
def post(self):
textInput = self.request.get('content').lower()
template = JINJA_ENVIRONMENT.get_template('index.html')
t1= time.time()
product_query = ndb.gql("SELECT * FROM Product where name >= :1 LIMIT 5",textInput)
results = product_query.fetch(5)
t2= time.time()
products = []
for counter, names in enumerate(results):
if counter == 0:
if not names.name.lower().startswith(textInput.lower()):
products.append("No Matches")
if names.name.startswith(textInput.lower()):
products.append(names.name)
queryTime = (t2 - t1) * 1000
template_values = {
'products': products,
'textInput': textInput,
'queryTime': queryTime,
}
self.response.write(template.render(template_values))
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
ありがとうございました –