iT邦幫忙

0

SelectField 求使用方法 !!

  • 分享至 

  • xImage

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!!!!

froce iT邦大師 1 級 ‧ 2022-03-29 08:04:43 檢舉
1. 請善用code block。
2. debug訊息請貼完整的。
碼農 iT邦新手 4 級 ‧ 2022-03-29 20:48:50 檢舉
好的 第一篇發問 拍謝
TypeError: The view function did not return a valid response.
The function either returned None or ended without a return statement.
froce iT邦大師 1 級 ‧ 2022-03-29 22:55:13 檢舉
debug訊息不是只有這幾行而已吧?

不過我猜是你的form.validate()沒過造成沒回傳導致的。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答