1

あるフォームから別のフォームに値を渡したいのですが、フォーム ウィザードを使用していません。私の見解:

def main_page(request):
    #if request.method == 'POST':
    #form = jobpostForm_first()
   # if request.method == 'POST':
    if request.method == 'POST':
       #if '_Submit'in request.POST:
            #if (form.data['post_type']=='Job'):
            form = jobpostForm_first(request.POST)
            if (form.data['post_type']=='Job'):

               #if form.is_valid():
                    #form.save()
                    return render_to_response('portal/job_post.html',{'form':form},context_instance=RequestContext(request))
            #else:
             #   return HttpResponseRedirect('/accounts/login/')

    else:
            form = jobpostForm_first()

    c = {}
    c.update(csrf(request))



    return render_to_response('portal/job_post.html',{'form':form},context_instance=RequestContext(request))


def next(request):
    #post_type= request.GET.get('post_type')

    if request.POST['post_type']=='Job': # here it is giving me exception "Key 'post_type' not found in <QueryDict: {}>"
       if request.method == 'POST':
            form = jobpostForm(request.POST)
            if form.is_valid():
                    form.save()

                    return HttpResponseRedirect('/thanks/')
       else:
            form = jobpostForm()
    else:
       return HttpResponseRedirect('/accounts/login/')

    c = {}
    c.update(csrf(request))

    return render_to_response('portal/job_post.html',{'form':form},context_instance=RequestContext(request))

post_type を 2 番目のフォームに渡したい。それに基づいて、他のフォームを表示したい。どうすればこれを行うことができますか?

4

1 に答える 1

3
def main_page(request):
    form = jobpostForm_first()

    if request.method == 'POST':
        form = jobpostForm_first(request.POST)
        if form.is_valid():
            post_type = form.cleaned_data['post_type']
            if post_type == 'Job':
                request.session['post_type'] = post_type
                return HttpResponseRedirect('/next/') //---> Is this the correct url for next?

    c = {}
    c.update(csrf(request))

    return render_to_response('portal/job_post.html',{
        'form':form
    },context_instance=RequestContext(request))


def next(request):
    if request.session.get('post_type') == 'Job': 
       if request.method == 'POST':
            form = jobpostForm(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/thanks/')
       else:
            form = jobpostForm()
    else:
       return HttpResponseRedirect('/accounts/login/')

    c = {}
    c.update(csrf(request))

    return render_to_response('portal/job_post.html',{
        'form':form
    },context_instance=RequestContext(request))
于 2013-03-20T12:55:00.087 に答える