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

111 views
Skip to first unread message

rick

unread,
Jul 5, 2012, 1:13:29 AM7/5/12
to django...@googlegroups.com

i want to filter roll no from database,but when i enter the number ,browser gives view didn't return an HttpResponse object ....this is my view..

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


please help...
thanks in advance.

dizzydoc

unread,
Jul 5, 2012, 2:22:21 AM7/5/12
to django...@googlegroups.com
The only condition where this view wont return an HTTPResponse is when request.method == 'POST' is True and form.is_valid() is False.

In this condition the outer if condtion would complete execution and exit out since inner if condition is False and wont enter inner if condition.

I think you should move out the return statement from the else loop.

manish girdhar

unread,
Jul 5, 2012, 2:59:35 AM7/5/12
to django...@googlegroups.com
thanks for the help friend..after manipulate that thing i got an error of

UnboundLocalError at /record_system/studentid/

local variable 'rollno' referenced before assignment

...
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/6178-1cjLacJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

manish girdhar

unread,
Jul 5, 2012, 3:08:56 AM7/5/12
to django...@googlegroups.com
thankssss ...i rectify this error.

kenneth gonsalves

unread,
Jul 5, 2012, 3:10:45 AM7/5/12
to django...@googlegroups.com
On Thu, 2012-07-05 at 12:29 +0530, manish girdhar wrote:
> thanks for the help friend..after manipulate that thing i got an error
> of*
> *UnboundLocalError at /record_system/studentid/
>
> local variable 'rollno' referenced before assignment

error in indentation - it is difficult to check this from your mail, so
please paste the code in dpaste.com so that we can see what the exact
indentation is.
--
regards
Kenneth Gonsalves

manish girdhar

unread,
Jul 5, 2012, 3:38:01 AM7/5/12
to django...@googlegroups.com
yes it was indentation error and i rectified that.thanks for the concern friend..

On Thu, Jul 5, 2012 at 12:40 PM, kenneth gonsalves <law...@thenilgiris.com> wrote:
On Thu, 2012-07-05 at 12:29 +0530, manish girdhar wrote:
> thanks for the help friend..after manipulate that thing i got an error
> of*
> *UnboundLocalError at /record_system/studentid/
>
> local variable 'rollno' referenced before assignment
ah
error in indentation - it is difficult to check this from your mail, so
please paste the code in dpaste.com so that we can see what the exact
indentation is.
--
regards
Kenneth Gonsalves
--
You received this message because you are subscribed to the Google Groups "Django users" group.

Tom Evans

unread,
Jul 5, 2012, 10:04:51 AM7/5/12
to django...@googlegroups.com
On Thu, Jul 5, 2012 at 8:38 AM, manish girdhar
<manishg...@gmail.com> wrote:
> yes it was indentation error and i rectified that.thanks for the concern
> friend..
>

I would have thought that it was you refering to the undefined
variable rollno here:

cd = form.cleaned_data
rollno = cd[rollno]
rollno = request.POST.get(rollno)

Should it not read:

cd = form.cleaned_data
rollno = cd["rollno"]
rollno = request.POST.get(rollno)

Cheers

Tom

manish girdhar

unread,
Jul 6, 2012, 4:49:22 AM7/6/12
to django...@googlegroups.com
hii tom,
yeah i have rectidy rollno = cd["rollno"] ,but again am getting error didn't get an httpresponse object...

this is my view.


def studentid(request):
    if request.method == 'POST':
        form = Student_loginForm(request.POST)
        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))


the error is in "if form.is_valid: "..its getting false and ultimately the further process is not going on..

thanks in advance.

Karl Sutt

unread,
Jul 6, 2012, 5:05:22 AM7/6/12
to django...@googlegroups.com
There is no HttpResponse object returned if the form is not valid. You might want to return a template saying that the form input was incorrect.

Tervitades/Regards
Karl Sutt

manish girdhar

unread,
Jul 6, 2012, 5:16:02 AM7/6/12
to django...@googlegroups.com
thank you for your concern friend,but i have an another view .in that it perfectly works....but here am getting problem and i know

 "if form.is_valid():"   is getting false....what am looking for is this, that why here am getting problem.
this thing perfectlly works in my adding two number view's appication.

Jani Tiainen

unread,
Jul 6, 2012, 5:19:46 AM7/6/12
to django...@googlegroups.com
Print out form.errors it will contain dictionary about fields and errors
in particular field.

You get the error because your form didn't validate in the first place
so either you have bad data, are missing required data or something else
in validation fails. form.errors will reveal that.

6.7.2012 12:16, manish girdhar kirjoitti:
> thank you for your concern friend,but i have an another view .in that it
> perfectly works....but here am getting problem and i know
>
> *"if form.is_valid():"* is getting false....what am looking for is
> this, that why here am getting problem.
> this thing perfectlly works in my adding two number view's appication.
>
>
> On Fri, Jul 6, 2012 at 2:35 PM, Karl Sutt <ka...@sutt.ee
> <mailto:ka...@sutt.ee>> wrote:
>
> There is no HttpResponse object returned if the form is *not* valid.
> You might want to return a template saying that the form input was
> incorrect.
>
> Tervitades/Regards
> Karl Sutt
>
>
>
> On Fri, Jul 6, 2012 at 11:49 AM, manish girdhar
> <manishg...@gmail.com <mailto:manishg...@gmail.com>> wrote:
>
> hii tom,
> yeah i have rectidy rollno = cd["rollno"] ,but again am getting
> error didn't get an httpresponse object...
>
> this is my view.
>
>
> def studentid(request):
> if request.method == 'POST':
> form = Student_loginForm(request.POST)
> 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))
>
>
> the error is in*"if form.is_valid: "*..its getting false and
> ultimately the further process is not going on..
>
> thanks in advance.
>
>
> On Thu, Jul 5, 2012 at 7:34 PM, Tom Evans
> <teva...@googlemail.com <mailto:teva...@googlemail.com>> wrote:
>
> On Thu, Jul 5, 2012 at 8:38 AM, manish girdhar
> <manishg...@gmail.com
> <mailto:manishg...@gmail.com>> wrote:
> > yes it was indentation error and i rectified that.thanks
> for the concern
> > friend..
> >
>
> I would have thought that it was you refering to the undefined
> variable rollno here:
>
> cd = form.cleaned_data
> rollno = cd[rollno]
> rollno = request.POST.get(rollno)
>
> Should it not read:
>
> cd = form.cleaned_data
> rollno = cd["rollno"]
> rollno = request.POST.get(rollno)
>
> 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...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@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...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@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...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@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...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--
Jani Tiainen

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


manish girdhar

unread,
Jul 6, 2012, 5:31:13 AM7/6/12
to django...@googlegroups.com
thanks for the concern firend but i already have an form.error in my template.......


this is my template..

<html>
<head>
    <title>student id</title>
</head>

<body style="background-color:pink;">
        {% if form.errors %}
        <p style="color: red;">
            Please correct the error{{ form.errors|pluralize }} below.
        </p>
    {% endif %}
     <h1><center>STUDENT RECORD SYSTEM</center></h1>
    <hr>
    <form action="" method="post">
    {% csrf_token %}

    <table><tr><td>Student Roll no:</td>
     <td><input type="text" name="rollno"></td><br /></tr></table>
     <input type="submit" value="Submit">
    </form>
   
   

</body>
</html>


On Fri, Jul 6, 2012 at 2:49 PM, Jani Tiainen <red...@gmail.com> wrote:
Print out form.errors it will contain dictionary about fields and errors in particular field.

You get the error because your form didn't validate in the first place so either you have bad data, are missing required data or something else in validation fails. form.errors will reveal that.

6.7.2012 12:16, manish girdhar kirjoitti:
thank you for your concern friend,but i have an another view .in that it
perfectly works....but here am getting problem and i know

*"if form.is_valid():"*   is getting false....what am looking for is

this, that why here am getting problem.
this thing perfectlly works in my adding two number view's appication.


On Fri, Jul 6, 2012 at 2:35 PM, Karl Sutt <ka...@sutt.ee
<mailto:ka...@sutt.ee>> wrote:

    There is no HttpResponse object returned if the form is *not* valid.

    You might want to return a template saying that the form input was
    incorrect.

    Tervitades/Regards
    Karl Sutt



    On Fri, Jul 6, 2012 at 11:49 AM, manish girdhar
    <manishg...@gmail.com <mailto:manishgirdhar88@gmail.com>> wrote:

        hii tom,
        yeah i have rectidy rollno = cd["rollno"] ,but again am getting
        error didn't get an httpresponse object...

        this is my view.


        def studentid(request):
             if request.method == 'POST':
                 form = Student_loginForm(request.POST)
                 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))


        the error is in*"if form.is_valid: "*..its getting false and

        ultimately the further process is not going on..

        thanks in advance.


        On Thu, Jul 5, 2012 at 7:34 PM, Tom Evans
        <teva...@googlemail.com <mailto:tevans.uk@googlemail.com>> wrote:

            On Thu, Jul 5, 2012 at 8:38 AM, manish girdhar
            <manishg...@gmail.com
            <mailto:manishgirdhar88@gmail.com>> wrote:
             > yes it was indentation error and i rectified that.thanks
            for the concern
             > friend..
             >

            I would have thought that it was you refering to the undefined
            variable rollno here:

                         cd = form.cleaned_data
                         rollno = cd[rollno]
                         rollno = request.POST.get(rollno)

            Should it not read:

                         cd = form.cleaned_data
                         rollno = cd["rollno"]
                         rollno = request.POST.get(rollno)

            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...@googlegroups.com
            <mailto:django-users@googlegroups.com>.

            To unsubscribe from this group, send email to
            <mailto:django-users%2Bunsu...@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...@googlegroups.com
        <mailto:django-users@googlegroups.com>.

        To unsubscribe from this group, send email to
        <mailto:django-users%2Bunsu...@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...@googlegroups.com

    To unsubscribe from this group, send email to

    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...@googlegroups.com.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

--
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...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Jani Tiainen

unread,
Jul 6, 2012, 5:38:01 AM7/6/12
to django...@googlegroups.com
It doesn't ever work since you should rerender form with current data
and errors if form.valid() returns false.

Currently your logic doesn't return _nothing_ if form.valid() is false

def studentid(request):
if request.method == 'POST':
form = Student_loginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
rollno = cd['rollno']
return
HttpResponseRedirect(reverse('record_system.views.search' , args=(rollno)))
# No else here, nothing is rendered!

else:
# This else is for if request.method == POST
form = Student_loginForm()
return render_to_response('add_record/studentid.html',
context_instance=RequestContext(request))


I suggest that you put last return one indent level to left so it will
always render either errored form or in case method was not POST empty form.

6.7.2012 12:31, manish girdhar kirjoitti:
> thanks for the concern firend but i already have an form.error in my
> template.......
>
>
> *this is my template..
> *
> <mailto:ka...@sutt.ee <mailto:ka...@sutt.ee>>> wrote:
>
> There is no HttpResponse object returned if the form is
> *not* valid.
>
> You might want to return a template saying that the form
> input was
> incorrect.
>
> Tervitades/Regards
> Karl Sutt
>
>
>
> On Fri, Jul 6, 2012 at 11:49 AM, manish girdhar
> <manishg...@gmail.com
> <mailto:manishg...@gmail.com>
> <mailto:manishgirdhar88@gmail.__com
> <mailto:manishg...@gmail.com>>> wrote:
>
> hii tom,
> yeah i have rectidy rollno = cd["rollno"] ,but again am
> getting
> error didn't get an httpresponse object...
>
> this is my view.
>
>
> def studentid(request):
> if request.method == 'POST':
> form = Student_loginForm(request.__POST)
> 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))
>
>
> the error is in*"if form.is_valid: "*..its getting
> false and
>
> ultimately the further process is not going on..
>
> thanks in advance.
>
>
> On Thu, Jul 5, 2012 at 7:34 PM, Tom Evans
> <teva...@googlemail.com
> <mailto:teva...@googlemail.com>
> <mailto:tevans.uk@googlemail.__com
> <mailto:teva...@googlemail.com>>> wrote:
>
> On Thu, Jul 5, 2012 at 8:38 AM, manish girdhar
> <manishg...@gmail.com
> <mailto:manishg...@gmail.com>
> <mailto:manishgirdhar88@gmail.__com
> <mailto:manishg...@gmail.com>>> wrote:
> > yes it was indentation error and i rectified
> that.thanks
> for the concern
> > friend..
> >
>
> I would have thought that it was you refering to
> the undefined
> variable rollno here:
>
> cd = form.cleaned_data
> rollno = cd[rollno]
> rollno = request.POST.get(rollno)
>
> Should it not read:
>
> cd = form.cleaned_data
> rollno = cd["rollno"]
> rollno = request.POST.get(rollno)
>
> 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...@googlegroups.com <mailto:django...@googlegroups.com>
> <mailto:django-users@__googlegroups.com
> <mailto:django...@googlegroups.com>>.
>
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>
>
> <mailto:django-users%__2Buns...@googlegroups.com
> <mailto:django-users%252Buns...@googlegroups.com>__>.
>
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <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...@googlegroups.com <mailto:django...@googlegroups.com>
> <mailto:django-users@__googlegroups.com
> <mailto:django...@googlegroups.com>>.
>
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>
> <mailto:django-users%__2Buns...@googlegroups.com
> <mailto:django-users%252Buns...@googlegroups.com>__>.
>
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <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...@googlegroups.com <mailto:django...@googlegroups.com>
> <mailto:django-users@__googlegroups.com
> <mailto:django...@googlegroups.com>>.
>
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>
> <mailto:django-users%__2Buns...@googlegroups.com
> <mailto:django-users%252Buns...@googlegroups.com>__>.
>
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <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...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
>
>
> --
> 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...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <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...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.

manish girdhar

unread,
Jul 6, 2012, 6:18:52 AM7/6/12
to django...@googlegroups.com
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..

        <mailto:manishgirdhar88@gmail.com>
        <mailto:manishgirdhar88@gmail.__com
        <mailto:tevans.uk@googlemail.com>
        <mailto:tevans.uk@googlemail.__com

        <mailto:tevans.uk@googlemail.com>>> wrote:

                     On Thu, Jul 5, 2012 at 8:38 AM, manish girdhar
                     <manishg...@gmail.com
        <mailto:manishgirdhar88@gmail.com>
                     <mailto:manishgirdhar88@gmail.__com

        <mailto:manishgirdhar88@gmail.com>>> wrote:
                      > yes it was indentation error and i rectified
        that.thanks
                     for the concern
                      > friend..
                      >

                     I would have thought that it was you refering to
        the undefined
                     variable rollno here:

                                  cd = form.cleaned_data
                                  rollno = cd[rollno]
                                  rollno = request.POST.get(rollno)

                     Should it not read:

                                  cd = form.cleaned_data
                                  rollno = cd["rollno"]
                                  rollno = request.POST.get(rollno)

                     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
                     <mailto:django-users@__googlegroups.com

        <mailto:django-users@googlegroups.com>>.


                     To unsubscribe from this group, send email to
        django-users+unsubscribe@__googlegroups.com
        <mailto:django-users%2Bunsu...@googlegroups.com>

        <mailto:django-users%__2Bunsu...@googlegroups.com
        <mailto:django-users%252Bunsubscribe@googlegroups.com>__>.


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

        <mailto:django-users@googlegroups.com>>.


                 To unsubscribe from this group, send email to
        django-users+unsubscribe@__googlegroups.com
        <mailto:django-users%2Bunsu...@googlegroups.com>
                 <mailto:django-users%__2Bunsu...@googlegroups.com
        <mailto:django-users%252Bunsubscribe@googlegroups.com>__>.


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

        <mailto:django-users@googlegroups.com>>.


             To unsubscribe from this group, send email to
        django-users+unsubscribe@__googlegroups.com
        <mailto:django-users%2Bunsu...@googlegroups.com>
             <mailto:django-users%__2Bunsu...@googlegroups.com
        <mailto:django-users%252Bunsubscribe@googlegroups.com>__>.


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

        To unsubscribe from this group, send email to
        django-users+unsubscribe@__googlegroups.com

        <mailto:django-users%2Bunsu...@googlegroups.com>.
        For more options, visit this group at
        http://groups.google.com/__group/django-users?hl=en
        <http://groups.google.com/group/django-users?hl=en>.



    --
    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...@googlegroups.com

    To unsubscribe from this group, send email to
    django-users+unsubscribe@__googlegroups.com

    <mailto:django-users%2Bunsu...@googlegroups.com>.
    For more options, visit this group at
    http://groups.google.com/__group/django-users?hl=en
    <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...@googlegroups.com.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


--
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...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Jani Tiainen

unread,
Jul 6, 2012, 6:30:05 AM7/6/12
to django...@googlegroups.com
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', ...)

manish girdhar

unread,
Jul 6, 2012, 6:36:55 AM7/6/12
to django...@googlegroups.com
hmmmmm  finally got it.....thanks for the quick reply friend......thanks alot.

manish girdhar

unread,
Jul 6, 2012, 6:43:31 AM7/6/12
to django...@googlegroups.com
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??

rick girdhar

unread,
Jul 6, 2012, 10:12:26 AM7/6/12
to django...@googlegroups.com
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..

Reply all
Reply to author
Forward
0 new messages