アプリを構築するためにPythonでGAEを使用しています。最初のページ (Index.html) に「アプリケーション」と「バージョン」の 2 つのドロップダウンがあります。データベースから最初のドロップダウンを動的に設定できます。最初のドロップダウンの選択に基づいて、2 番目のドロップダウンに入力する必要があります。onchange イベントと JavaScript を使用して、最初のドロップダウン リストで選択 ID を取得しようとしました。しかし、キャプチャした onchangeid をバックエンドに渡す方法がわかりません。request.get が機能していないようです。どんな助けにも感謝します。
私のmain.pyは次のようになります
class MainPage(webapp.RequestHandler):
def get(self):
proj = db.GqlQuery("SELECT DISTINCT Applicationname FROM Dashboard")
Appname1 = self.request.get('selvalue.value')
proj1 = Dashboard.all().filter('Applicationname =',Appname1)
values = {'appnames' : proj, 'vernums' : proj1}
self.response.out.write(template.render('index.html',values))
class Dashboard(db.Model):
Applicationname = db.StringProperty(required=True)
Version=db.StringProperty(required=True)
Type=db.StringProperty()
Pagename=db.StringProperty(required=True)
Responsetime=db.StringProperty(required=True)
class DisplayHandler(webapp.RequestHandler):
def post(self):
Appname=self.request.get('Applicationname')
Vernum=self.request.get('Version')
query = Dashboard.all().filter('Applicationname =',Appname).filter('Version =',Vernum)
values = {'query' : query}
self.response.out.write(template.render('response.html',values))
def main():
application = webapp.WSGIApplication(
[('/', MainPage),
('/Display', DisplayHandler)
],
debug=True)
run_wsgi_app(application)
if __name__ == "__main__":
main()
私のindex.htmlは次のようになります
<html>
<head>
<title> My First Web Page </title>
<link rel="stylesheet" type="text/css" href="style.css"> </link>
<script type="text/javascript">
function myFunction(Applicationname)
{
var selvalue = document.getElementById("Applicationname");
}
</script>
</head>
<body>
<form action="/Display" method="post">
<select name="Applicationname" id="Applicationname" onchange="myFunction()" >
<option value="Select">---Select---</option>
{% for q in appnames %}
<option value="{{q.Applicationname}}">{{q.Applicationname}}</option>
{% endfor %}
</select>
<br><br>
Select the Version number
<select name="Version" id="Version">
<option value="Select">---Select---</option>
{% for r in vernums %}
<option value="{{q.Version}}">{{r.Version}}</option>
{% endfor %}
</select>
<input type="submit" value="Submit" align="center"/>
</form>