gpt4 book ai didi

django - 如何从django下拉框中获取值?

转载 作者:行者123 更新时间:2023-12-04 01:52:15 28 4
gpt4 key购买 nike

我应该使用下一个结构吗?

def PageObjects(request): 
q = bla_bla_bla(bla_bla)
answer = request.POST['value']


<form action="PageObjects" method="get">
<select >
<option selected="selected" disabled>Objects on page:</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<input type="submit" value="Select">
</form>


我怎么解决这个问题?我需要写些什么?

最佳答案

我建议您发送带有后的数据:

<form action="PageObjects" method="post">
<select >
<option selected="selected" disabled>Objects on page:</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<input type="submit" value="Select">
</form>


并且您应该通过 cleaned_data字典访问表单值:

def page_objects(request):
if request.method == 'POST':
form = YourForm(request.POST)

if form.is_valid():
answer = form.cleaned_data['value']


我真的建议您阅读Django文档:

https://docs.djangoproject.com/en/1.4/topics/forms/#using-a-form-in-a-view

关于django - 如何从django下拉框中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11586038/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com