我是一个初学者,因此请考虑到这一点,因此,我需要传递页脚和日期函数,而我莫名其妙地在这里漏了一点
from flask import Flask, render_template
from datetime import datetime
app = Flask("Timer Workout")
@app.route("/")
def Landing():
return render_template("Landing_Page.html")
def footer():
footerdb = open("footer.txt")
for i in range (3):
footerdb.write("footer.txt" + " by Carlos Teixeira")
footerdb.close()
return footerdb
同样在这里,我无法传递日期功能,我不知道该怎么办。帮助表示赞赏。非常感谢。
# basically i have to defined a route its not defined????
@app.route("/index.html/")
def Home():
return render_template("index.html")
def date():
return ('Current Date and Time: {}'.format(datetime.datetime.now()))
if "Timer Workout" == "__main__":
app.run()
该函数不返回任何东西,因为它没有被调用。
您希望将日期/时间返回哪里?
如果在/index.html中,则应执行以下操作:
然后可以在模板中将变量添加到HTML代码中,例如:
Basically you can define variables values inside your python main script. Pass them as arguments to the render_template function and then use them inside your template with
{{ your_var }}
.Have a look here : https://jinja.palletsprojects.com/en/2.11.x/templates/