使用Flask返回Html属性

2024-05-15 23:17:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图根据条件返回填充颜色,但这会将颜色发送到所有标签。请告诉我如何在烧瓶中使用“This.”或“Self”函数

@app.route('/body/<part>')
def show_blog(part):
    claim = int(Assembled_ClaimsDF.loc[part])
    if claim>10000:
        return redirect(url_for('colour_red'))
    else:
        return redirect(url_for('colour_green'))

@app.route('/colour_red')
def colour_red():
    return render_template('new.html', colour = 'red')

@app.route('/colour_green')
def colour_green():
    return render_template('new.html', colour = 'yellow')

@app.route('/')
def index():
    return render_template('new.html')

if __name__ == '__main__':
   app.run()

Tags: appnewreturnif颜色defhtmltemplate