- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在 Flask 中构建一个应用程序,它从不同的 CSV 文件中获取数据。我有不同的标签(CSV 文件中的列名称),对于每个标签,我有相同的下拉菜单。例如-
首先,我尝试创建这个模板。这是我的代码-
<div class="container">
<form class="col s12" action="/config" method="POST" enctype="multipart/form-data">
<div class="row">
<h2>Assign Fieldnames</h2>
{% for x in title %}
<label> {{ x }} :</label>
<select name="choice">
<option value="">Select One</option>
<option value="time">Temporal</option>
<option value="single">Single Choice</option>
<option value="multiple">Multiple Choice</option>
</select>
{% endfor %}
<input type="hidden" name="filename" value= {{filename}}></input>
<button class="btn" type="submit" value="Update">Submit</button>
</div>
</form>
</div>
查看
def config():
filepath = request.form['filename']
choice_to_make = ['Select one', 'Temporal', 'Single-Choice''Multi-
Choice']
print(filepath)
with open(filepath,'r') as csvfile:
reader = csv.reader(csvfile)
title = next(reader)
print(title)
return render_template('pages/placeholder.configure1.html',
title=title,choice_to_make= choice_to_make,
filename=filepath)
其次,我无法弄清楚如何为每个标签保存这些选择(多选、单选和临时),以便我可以在将此 CSV 发送到 Mongodb 后根据这些选择查询数据。
最佳答案
第一步是将每个标签选择选项与唯一的特定名称相匹配,以便能够在以下 View 中将它们关联起来。
模板
您可以使用循环索引来执行此操作。
{% for name in title %}
<label> {{ name }} :</label>
<select name="choice-{{ loop.index }}">
<option disabled selected value> Select One</option>
<option value="time">Temporal</option>
<option value="single">Single Choice</option>
<option value="multiple">Multiple Choice</option>
</select><br>
{% endfor %}
查看
下一步,在 View 中,您可以将表单给出的选择存储在字典或元组列表中(请参阅第二个建议)。重要的是采用一种能够在标题和选项之间保持轻松匹配的结构。
如果你想接下来调用特定的标题,字典会更有趣:
@app.route("/config", methods=['POST'])
def config():
choices = {}
with open(request.form['filename'], 'r') as csvfile :
reader = csv.reader(csvfile)
titles = next(reader)
for index, title in enumerate(titles,1):
choice = 'choice-' + str(index)
choices[title] = request.form.get(choice)
#choices = {'Mode of Transport': 'time', 'Timestamp':'multiple' }
<小时/>
列表可能更好地处理连续的所有标题并保持顺序:
choices = []
with open(request.form['filename'], 'r') as csvfile :
reader = csv.reader(csvfile)
titles = next(reader)
for index, title in enumerate(titles,1):
choice = 'choice-' + str(index)
choices.append((title, request.form.get(choice))
#choices = [('Mode of Transport','time'), ('Timestamp','multiple')]
关于python - 如何为不同的标签创建相同的下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46841928/
我试图让我的 jQuery 脚本从单击的链接中提取 url,然后将其插入到我的视频标签中。有什么建议吗? 我试过拼接我从 .html() 中得到的内容,但引号总是搞砸了。
我遇到了 docker 的问题。 场景是这样的:我们使用Codebuild+Packer+docker创建AMI,用于deploy。在这一步中,我们从 Artifactory 中提取图像,并且除了提取
我目前正在学习 RxJS。 在文档中,我找到了这个数组。 我尝试在谷歌上搜索“pull and push javascript”,但我什至不知道如何调用这些实体/概念。我不明白那是什么意思?我假设 S
Title 在小屏幕上,我首先需要标题,然后是文本字段,但在中等以上的屏幕上,我需要相反的方式 - 我已经尝试过推和拉,但它们无法工作 - 有什么想法吗? 最佳答案 根据 Swa
zmq 的某些部分未以可预测的方式运行。 我正在使用 VS2013 和 zmq 3.2.4。为了不在我的 pubsub 框架中“丢失”消息 [旁白:我认为这是一个设计缺陷。我应该能够首先启动我的订阅者
我正在编写一个使用嵌套 Bootstrap 列的页面。我正在使用推/拉让列在移动设备上切换位置,而且效果很好。但是,在桌面上我遇到了一些奇怪的间距问题。嵌套列偏移到父列的右侧。 我设置了一个 fidd
在拉取一些 docker 镜像(但不是全部)时出现此错误: failed to register layer: Error processing tar file(exit status 1): op
我创建了一个 Kubernetes 集群,并为每个节点安装了 docker。 当我尝试使用 docker push local_registry_addr:port/image_id 将图像拉取或推送
没有明确地推/拉单个书签,书签何时从 repo 复制/更新到 repo? 在我对两个本地存储库的测试中,我无法推断出一致的行为。有时从 A 到 B 或 B 到 A 的推/拉会复制/更新书签,有时不会。
在 Bootstrap 3 文档中,他们给出了以下使用 push 和 pull 类更改列顺序 (http://getbootstrap.com/css/#grid-column-ordering) 的
从这个问题开始Three column Bootstrap layout with left sidebar at bottom我了解了 Bootstrap 列推拉。 下面的代码片段几乎可以得到我想要
许多 Repo 函数的签名包括 **kwargs,其中文档说,您可以将参数传递给底层包装的 git 命令。但是,*args 没有位置。为了传递类似标志的参数,如 --all。我原以为它们会像 my_r
如果您将大文件推送/拉到设备上,这真的很烦人,现在无法知道它有多远。是否可以运行 adb push 或 adb pull 并使用“bar”实用程序获取进度条? 这里的主要问题是我认为 adb 需要两个
当我尝试使用 Gitkrakent 向/从 Heroku 推/拉时,GitKraken 告诉我: "Please log in to continue" 请求的“用户/登录”是什么? (我个人 Her
我在 docker 容器中有一个 Jenkins 2.150.1。要安装这个 Jenkins,我只需使用 jenkinsci/blueocean:1.9.0图片。 我创建了一个管道,然后尝试使用我的
我想使用 Jenkins 做下一步: 1- docker pull 2- docker run -i -t 我已经在jenkins上安装了docker插件,但是这可行吗? docker plugi
如果我正在处理一些我不想提交的文件,我只需保存它们。然后我有其他文件想要推送到服务器,但是如果其他人对存储库进行了更改,并且我将它们拉下来,它会要求我 merge 或 rebase ..但是这些选项中
无论出于何种原因,我在 FB 上共享链接时尝试使用的图像都无法加载。给出的确切错误是: 提供了og:image,无法下载。发生这种情况的原因有多种,例如您的服务器使用不受支持的内容编码。爬虫接受 de
今天我买了三星 Galaxy Note 3,它配备了 Android 4.3。由于它太新了,我找不到根植我设备的方法,所以我尝试使用 adb 连接……我失败了。 所以,我用了这个 D:\android
我尝试通过 airflow cli test 命令测试 2 个任务` 第一个任务运行,自动将最后一个控制台推送到 xcom,我按预期在 Airflow GUI 中看到了值 some value 当我通
我是一名优秀的程序员,十分优秀!