Django 验证并返回预览 URL?
我再次询问:),我不知道如何做到这一点。
我的英语不太好,但我会尝试问这个:
如何验证表单并返回预览网址(相同的视图表单)并显示验证错误?我问这个是因为我有 2 个表单,第一个表单的操作将转到第二个表单(POST),但是在第二个表单(视图?)中,我需要验证第一个表单,如果第一个表单有效,我想显示第二个表单,否则将显示第一个表单,其中有错误。
我不知道我是否清楚,抱歉。
我正在考虑这个:
def secondForm(request):
if request.method =='POST':
form = FirstForm(request.POST)
if form.is_valid():
fields = request.POST.copy()
# showing the second form?? with x differents fields, i have 2.
if fields['xvalue']=='1': # this is from radio buttons
form2 = xSecondForm()
elif fields['xvalue']=='2':
form2 = ySecondForm()
else:
# here go back with erros msgs????
#return render_to_response('firstFormTemplate.html',{'form': form}, context_instance=RequestContext(request))
else:
#return something or go back ???
谢谢大家 PD:我很高兴,我正在编码 Django + python :D
im asking again :), i don't know how make this.
My English is not too good, but ill try to asking this:
how ill validate a form and go back to the preview url (the same view form) and show the validation errors?, im asking this because i have 2 form's, the first form's action is going to a second form (POST), but in this second form (view?) i need to validate the first form, if the first form is valid i want to show the second form else ill show the first form with errors.
i dont know if im clear , im sorry.
im thinking about this:
def secondForm(request):
if request.method =='POST':
form = FirstForm(request.POST)
if form.is_valid():
fields = request.POST.copy()
# showing the second form?? with x differents fields, i have 2.
if fields['xvalue']=='1': # this is from radio buttons
form2 = xSecondForm()
elif fields['xvalue']=='2':
form2 = ySecondForm()
else:
# here go back with erros msgs????
#return render_to_response('firstFormTemplate.html',{'form': form}, context_instance=RequestContext(request))
else:
#return something or go back ???
Thanks guys
PD: im happy, im coding Django + python :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,formwizard 可能是您的答案,但您可能可以在视图中使用一些逻辑来做到这一点。
就像是:
Yes, formwizard might be your answer, but you could probably do it with some logic in a view.
Something like:
好吧,伙计们,我认为我的解决方案是 FormWizard :)
但我不清楚我的第二个表单,因为如果无线电中选定的选项用于更多或更少的字段(在第二种形式)
;(
Ok, guys, i think that mi solution is FormWizard :)
but im not clear with something about my Second Form, because i need to show the second form in different way if the selected option in radio is for more or less fields (in the second form)
;(
我认为您想使用 process_step() 来对第二种形式中如何显示/显示什么进行一些逻辑。
I think you want to use process_step() to do some logic on how/what do display in your second form.