我正在使用Python Flask来托管一个web服务器,它主要工作。我理解这个问题,但我不知道如何解决它。我知道在显示的代码中,当网站第一次启动时,它呈现模板,变量“CurtainCloseTime”没有赋值。所以我有两个表格在我的网站上,我输入一个时间,窗帘关闭和打开,因此变量名称。变量“CCT”表示CurtainCloseTime,是HTML文件中的变量,因为我希望它显示回web页面。在
下面是Python烧瓶代码:
@app.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST': #If there is an input from form
CurtainOpenTime = request.form['CurtainOpenTime'] #Assign CurtainOpenTime variable in python to the html CurtainOpenTime variable.
CurtainCloseTime = request.form['CurtainCloseTime'] #Assign CurtainCloseTime variable in python to the html CurtainCloseTime variable.
return render_template('Index.html', CCT=CurtainCloseTime)
首先,我认为你的问题有缩进问题。我想你的实际代码是:
如果这是您的代码(但我们不能确定),那么如果http方法是'GET',CCT就没有值。必须在“if”语句之外指定它:
^{pr2}$相关问题 更多 >
编程相关推荐