On Wed, Oct 17, 2012 at 9:45 AM, lovetoprogram <stanbell2...@gmail.com> wrote:
> Hi,
>
> I am new to Django and I was creating a basic site with it. But I have
> encountered a problem.
>
> In the following code, I have a webpage with form and when submit button is
> clicked, the parameters have to be passed into a results page for display.
> When I keep render_to_response of the results page, the results page is
> shown instead of the main page.
>
> How to solve this problem?
>
> def mix(request):
>     if request.method == 'GET':
>
>         valueList = []
>         valueListInt = []
>         for i in range(1,20):
>             questionNum = ('qn'+str(i))
>             valueList.append(request.GET.getlist(questionNum))
>         #return redirect('mixResult.html', {'qn1Ans':str(valueList[0]),
> 'qn2Ans':valueList[1], 'qn3Ans':valueList[2], 'qn4Ans':valueList[3],
> 'qn5Ans':valueList[4], 'qn6Ans':valueList[5], 'qn7Ans':valueList[6],
> 'qn8Ans':valueList[7], 'qn9Ans':valueList[8], 'qn10Ans':valueList[9],
> 'qn11Ans':valueList[10], 'qn12Ans':valueList[11], 'qn13Ans':valueList[12],
> 'qn14Ans':valueList[13], 'qn15Ans':valueList[14], 'qn16Ans':valueList[15],
> 'qn17Ans':valueList[16], 'qn18Ans':valueList[17], 'qn19Ans':valueList[18],})
>         total = 0
>         for i in range(len(valueList)):
>             total = total + i
>         print 'total', total
>         if total == 171:
>             print 'wooooooooooooooooohooooooooooooooo'
>
>         return render_to_response('mix.html')
>

To redirect to a different page, return a HttpResponseRedirect with
the URL you want to go to:

https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpResponseRedirect

To generate the url to go to from a view name, or a view function
identifier, use the reverse function:

https://docs.djangoproject.com/en/1.4/topics/http/urls/#reverse

If you wish to pass additional arguments along with this redirect, you
must encode them into the query string. To do this, you can use the
QueryDict class:

https://docs.djangoproject.com/en/1.4/ref/request-response/#querydict-objects

Put together, this looks something like this:

  data = QueryDict('',mutable=True)
  data['hello'] = '1'
  url = reverse('my_view_function')
  query_str = data.urlencode()
  return HttpResponseRedirect('%s?%s' % (url, query_str))

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to