1.html page
<form method='post' action="{{url_for ('Select')}}">
{{ form.pla.label }}
{{ form.pla}}
<input type=submit name="see" value='chinese查詢'>
</form>
2.app page
erro = []
@ app.route('/', methods=['GET','POST'])
def Select():
if request.method == 'GET':
session.clear()
form = m.SelectForm()
return render_template('index.html', form=form)
else:
form = m.SelectForm(request.form)
if request.method =='POST' and form.validate():
pla = request.form['pla']
detail= m.sql_read()
for i in detail:
if pla in i[0]:
erro.append(i)
return render_template('index.html',form=form,erro=erro)
3.module page
def sql_read(): #this def is successful take sql data
connection = pymysql.connect(host='xxxxxxxx',
port=xxxxx,
user='root',
password='xxxxxx',
database='xxxxx',
charset='utf8mb4')
with connection:
with connection.cursor() as cursor:
sql = "SELECT * FROM `Dajia_District` "
cursor.execute(sql)
rows=cursor.fetchall()
connection.commit()
return list(rows)
#==============================================
class SelectForm(Form):
add = StringField(
'輸入路名:', validators=[validators.DataRequired(message='Not Null')])
pla = SelectField('選取地區', choices=[('Daiaj','大甲區'),('travel','旅遊'),('movie','電影')])
Can anyone please help me on this !!Thanks!!!!