我正在使用以下代码从Django模板上的CSV文件填充唯一数据。
这是我的view.py代码
df = pd.read_csv("statics/chicago_crime_2016.csv")
columns = df.columns
primary_type = df['Primary Type'].unique()
def index(request):
context = {'primary_type': primary_type, 'columns': columns}
return render(request, 'index.html', context)
这是我的HTML代码:
<div class="container-fluid mt-4">
<select>
{% for column in columns%}
<option value="{{ column }}">{{ column }}</option>
{% endfor %}
</select>
<select>
{% for type in primary_type%}
<option value="{{ type }}">{{ type }}</option>
{% endfor %}
</select>
</div>
接下来,当我从第一个下拉列表中选择一列时,我想要的是什么,然后它在第二个下拉列表中显示了在第一个下拉列表中选择的列值。现在,它只显示一个列值,它是静态的,我想要一个动态下拉列表,该下拉列表根据情况进行更改。