我已经用mysql创建了一个数据库,一个html和python代码,如下所示。如果有人能指出我做错了什么,那真的很有帮助。 html代码不存在加载。需要“从目的地”的下拉列表。但是取而代之的是{{tvalue}} HTML代码如下:(kalyani.html)你知道吗
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BlueBus</title>
</head>
<body>
<form action="{{ url_for('bluebus') }}" method="POST">
Date of Travel: <input type="date" name=""><br>
From Destination: <select name= 'tvalue'>
{% for tvalue in data%}
<option value="{{ tvalue }}" selected='selected'>{{ tvalue }}</option>
{% endfor %}
</select>
To Destination: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
</body>
Python代码如下:
import pymysql
import flask
import simplejson as JSON
def data(): # Execute query
hostname='127.0.0.1'
username= 'root'
password= '******'
Database= 'mainkar'
myconnection = pymysql.connect(host=hostname, user=username, password=password, database= Database,autocommit=True)
cursor=myconnection.cursor()
sql = 'SELECT distinct(from_city) from route'
# Parse in a variable into the query
cursor.execute(sql)
list_tested = cursor.fetchall() # Get query response and store in variable
list_tested = [i for sub in list_tested for i in sub] # Convert to list from tuple
return (list_tested)
x=data()
htmlFilename = 'kalyani.html'
htmlFile = open(htmlFilename, 'w')
app = flask.Flask(__name__)
@app.route('/bluebus',methods=['POST', 'GET'])
def bluebus():
x=data()
data = x # you can get list from your DB instead
data['selected_tvalue'] = tvalue
return flask.render_template('kalyani.html', **data)
当函数按以下方式更改时,问题得到解决 &燃气轮机
>
相关问题 更多 >
编程相关推荐