1

I want to pass value from one form to another but i am not using form wizard. my views:

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))

I want pass the post_type to 2nd form.and on its basis i want to show other form. Can anyone tell me how can i do this?

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 回答