基于Python变量的HTML默认值fo广播按钮输入类型
因此,即时通讯在使用用户上传电子表格,然后可以在HTML页面上使用该电子表格的参数进行播放。一个参数是一个只能是1、2或3的值。用户能够通过选择带有这些选项的单选按钮来更改此值。
这一切都很好,但是我希望广播按钮的默认值是用户上传的初始电子表格中的任何内容。
我的想法是做类似的事情:
main.py
@app.route('/', methods=['GET','POST'])
def params_form():
value = 2
value_dict = {'1': 1==value, '2': 2==value, '3': 3==value}
return render_template('home/sheet.html', value_dict)
Sheet.html
<div>
<input type="radio" id="n1" name="nyears" value=1 checked={{value_dict["1"]}}>
<label for="n1"> 1 </label>
<input type="radio" id="n2" name="nyears" value=2 checked={{value_dict["2"]}}>
<label for="n2"> 2 </label>
<input type="radio" id="n3" name="nyears" value=3 checked={{value_dict["3"]}}>
<label for="n3"> 3 </label>
</div>
,但不幸的是,对“检查”属性的任何使用都会检查框(在这种情况下,这是最后使用检查属性的属性)。似乎拥有默认检查值的唯一方法是仅在一个输入行上使用检查属性。
任何帮助使此工作的工作将不胜感激 提前致谢!
so im making a Flask app where a user uploads a spreadsheet and then can play with the parameters of that spreadsheet on a html page. One parameter is a value which can only be 1, 2 or 3. The user is able to change this value by selecting a radio button with these options.
This all works fine but i would like the default value of the radio button to be whatever was in the initial spreadsheet that the user uploaded.
my idea was to do something like this:
main.py
@app.route('/', methods=['GET','POST'])
def params_form():
value = 2
value_dict = {'1': 1==value, '2': 2==value, '3': 3==value}
return render_template('home/sheet.html', value_dict)
sheet.html
<div>
<input type="radio" id="n1" name="nyears" value=1 checked={{value_dict["1"]}}>
<label for="n1"> 1 </label>
<input type="radio" id="n2" name="nyears" value=2 checked={{value_dict["2"]}}>
<label for="n2"> 2 </label>
<input type="radio" id="n3" name="nyears" value=3 checked={{value_dict["3"]}}>
<label for="n3"> 3 </label>
</div>
But unfortunately, any use of the 'checked' attribute will check the box (in this case number 3, as it is the last to use the checked attribute). It seems that the only way to have a default checked value is to only use the checked attribute on one input line.
Any help getting this to work will be greatly appreciated
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
render_template
中以关键字的方式设置变量名:You need to set the variable name in
render_template
by passing it as keyword: