python-3.x - The foreign key id cannot loaded in drop-down list in Django temlate
问题描述
In the entry.id
cannot fetch the data from table. And I also save the selected option to store in another table. How can I do this?
register.html
<form method="POST">
<select name="item_id">
{% for entry in items %}
<option value="{{ entry.id }}">{{ entry.name }}</option>
{% endfor %}
</select>
</form>
解决方案
只需传递条目名称而不是选项标签
<form method="POST">
<select name="item_id">
{% for entry in items %}
{{ entry.name }}
{% endfor %}
</select>
</form>
它将自动采用选项标签
推荐阅读
- powershell - 如何将多行批处理文件语句转换为 Powershell?
- google-analytics - 在 GTM 创建虚拟页面并将其发送到 GA 的问题
- python-3.6 - 为什么 -1*List 对象返回一个空列表?
- sql-server - 签名存储过程和应用程序角色安全冲突
- python - 如何在 docker 容器中使用相机
- python - 使用 Python 解析 xml 以提取 div 之间的内容
- javascript - 为什么反应应用程序的 node_modules/.cache/babel-loader 文件夹中有数百个 json 文件?
- android - 选项卡布局过渡延迟非常快
- matlab - 从单元格中绘制数据
- windows - 在连接多个文件时添加新行