我有点糊涂了,希望你能帮我,
我有一个类似于下面的文本文件:
./Video/SetUp
./Video/NewRecordings
./Video/NewRecordings/20160113_151920
./Video/Back Up
./Video/Back Up/FirstLecDraft
./Video/Back Up/FirstTalk我使用下面的python脚本(感谢独占)使用上面提到的List文本文件填充html文件:
import dominate
from dominate.tags import *
doc = dominate.document(title='Dominate your HTML')
with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with doc:
with div():
with open('List') as f:
for line in f:
li(input(line.title(), type='submit', value='%s' % line, onclick='self.location.href=\'http://127.0.0.1:5000/{This must be the same as "value" part}\''))
with div():
attr(cls='body')
print doc第一个问题:如何将value字段的值传递给onclick上路径的其余部分
其结果肯定是这样的:
<input href="" onclick="self.location.href='http://127.0.0.1:5000/cameradump/2016-01-21" type="submit" value="./cameradump/2016-01-21">和另一个按钮的另一个值。
如您所见,:5000/后的onclick路径的其余部分必须与value字段完全相同。
第二个问题:我如何将它传递给烧瓶的main.py文件上的路由?(例如,当用户按下每个按钮时,必须将该按钮的值动态设置为路由)
main.py现在是这样的:
from flask import Flask, render_template
import subprocess
app = Flask(__name__)
@app.route("/{value must be passed here}")
def index():
return render_template('index.html')
...但是,如果用户按下/cameradump/2016-01-21按钮,它应该如下所示
...
@app.route("/cameradump/2016-01-21")
def index():
return render_template('index.html')
...或者根据按下的按钮计算另一个值。
发布于 2016-01-28 22:12:56
First:
与使用value的方法相同--使用%
onclick='self.location.href="http://127.0.0.1:5000/%s"' % date如果您不能在文件"2016-01-21"中使用"List",但是您有"/cameradump/2016-01-21",那么您可以拆分它(使用"/")并获得最后一个元素日期。
# `line` is `"/cameradump/2016-01-21"`
data = line.split('/')[-1]第二版:
阅读关于路由的文档
您可以在路径中使用变量来获取日期。
@app.route("/cameradump/<date>")
def index(date):
print("Date:", date)
return render_template('index.html')https://stackoverflow.com/questions/35072767
复制相似问题