gpt4 book ai didi

python - 为什么我的初始值没有为我的 Django 表单设置?

转载 作者:太空宇宙 更新时间:2023-11-04 01:40:16 25 4
gpt4 key购买 nike

这里是相关的片段

表单.py

usersegment = [['non-paying','Non-paying (Coming soon)'],['paying','Paying (Coming soon)'], ['all', 'All']]

class SegmentForm(forms.Form):
usersegment = forms.ChoiceField(label="", widget=RadioSelect(), choices=usersegment)

views.py

if request.method == 'GET' and 'datestart' in request.GET:

return render_to_response('activation/activation_signupcount.html',
{ 'datestart': request.GET['datestart'],
'dateend': request.GET['dateend'],
'usersegment': request.GET['usersegment'],
'form': SegmentForm(request.GET),
'form2': DateSelectForm(request.GET) })
else:

return render_to_response('activation/activation_signupcount.html',
{'form': SegmentForm(initial={'all':'All'}), 'form2': DateSelectForm()})

最佳答案

首字母是键:值(字段名/值)对。它应该是这样的,

else:
return render_to_response('activation/activation_signupcount.html',
{'form': SegmentForm(initial={'usersegment':'all'}),
'form2': DateSelectForm()
})

关于python - 为什么我的初始值没有为我的 Django 表单设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5853806/

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