Friday, July 6, 2012

Re: view didn't return an HttpResponse object....plz help

after entering number in the template page .am getting the error,that is:

NoReverseMatch at /record_system/studentid/

Reverse for 'record_system.views.search' with arguments '(None,)' and keyword arguments '{}' not found.



and this is my new updated view..


def search(request , rollno):
results = Add_record.objects.filter(Student_ID = rollno)
return render_to_response('add_record/search.html', locals(), context_instance=RequestContext(request))


def studentid(request):
if request.method == 'POST':
form = Student_loginForm(request.POST)
rollno = request.POST.get('rollno')
if form.is_valid():
cd = form.cleaned_data
rollno = cd['rollno']
return HttpResponseRedirect(reverse('record_system.views.search' , args=(rollno,)))
else:
form = Student_loginForm()
return render_to_response('add_record/studentid.html', context_instance=RequestContext(request))


please help i can't able to find the solution as am new bie to the django...

thank you..



On Fri, Jul 6, 2012 at 4:13 PM, manish girdhar <manishgirdhar88@gmail.com> wrote:
hmmm i can find my solution after inserting this line

rollno = request.POST.get('rollno')

and this was the coding part of my application ,but can you please tell me that why my " if form.is_valid(): "  is not working..what's wrong in this??


On Fri, Jul 6, 2012 at 4:06 PM, manish girdhar <manishgirdhar88@gmail.com> wrote:
hmmmmm  finally got it.....thanks for the quick reply friend......thanks alot.


On Fri, Jul 6, 2012 at 4:00 PM, Jani Tiainen <redetin@gmail.com> wrote:
6.7.2012 13:18, manish girdhar kirjoitti:

so sorry friend..am new to the django and am unable to catch your
point...can you please describe this with example or with my code..thank
you..

[Snip snip with binary scissors]

Problem is that there is two problem points:

Your view doesn't have "default path" so
IF request.method is POST and IF form.is_valid is FALSE your code doesn't return anything.

This means that your view will return something only if request.method is not POST (return render_to_response(...) is called) or if request.method is POST and form.is_valid() is true (return HttpResponseRedirect(..) is called)

Simplest way to fix it is to indent last "return render_to_response..." one level outer (same level as if request.method == 'POST' and last else) making it to be executed if request.method is not POST or if form.is_valid() is false.

In short form:


def studentid(request):
    if request.method == 'POST'
        form = Student_loginForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect(...)
    else:
        form = Student_loginForm()
    return render_to_response('add_record/studentid.html', ...)



--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment