【发布时间】:2012-07-12 11:12:28
【问题描述】:
我想使用 python、html 和 javascript 构建一个桌面应用程序。到目前为止,我已经按照烧瓶上的 tuts 并有一个 hello world 工作示例。我现在应该怎么做才能让它工作? html 文件如何与它们下面的 python 脚本“对话”?
这是我目前的代码:
from flask import Flask, url_for, render_template, redirect
app = Flask(__name__)
@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
return render_template('hello.html', name=name)
@app.route('/')
def index():
return redirect(url_for('init'))
@app.route('/init/')
def init():
css = url_for('static', filename='zaab.css')
return render_template('init.html', csse=css)
if __name__ == '__main__':
app.run()
【问题讨论】:
-
HTML 文件从不与 Python 脚本“对话”。 Python(通过 Flask)将使用 Jinja2 使用您传递给 render_template() 的任何信息来呈现 HTML 文件。你应该在这里完成教程:flask.pocoo.org/docs/tutorial/introduction 之后事情会变得更有意义。
-
好吧,这是有道理的,但我怎么能传递数据呢?例如。从表单传递一些数据
标签: javascript python html flask