librelist archives

« back to archive

Getting error when using request.method == post

Getting error when using request.method == post

From:
Rahul R
Date:
2010-06-06 @ 05:00
Well i apologise that i am posting the script in pastebin

http://pastebin.com/36juUM3X

when i am using request.method = 'POST'  , i am getting an error or else it
works fine


Rahul

Re: [flask] Getting error when using request.method == post

From:
Peter Ward
Date:
2010-06-06 @ 05:51
You might like to try running your application with debug mode on.
Just change app.run() to app.run(debug=True).
(obviously, you should disable this when you deploy your application)

The problem is that "request is undefined", which is because you haven't
imported it from the flask module.
from flask import Flask, *request, *render_template

Regards,
  Peter

On Sun, Jun 6, 2010 at 3:00 PM, Rahul R <rahul8590@gmail.com> wrote:

> Well i apologise that i am posting the script in pastebin
>
> http://pastebin.com/36juUM3X
>
> when i am using request.method = 'POST'  , i am getting an error or else it
> works fine
>
>
> Rahul
>
>
>

-- 
Peter Ward
http://flowblok.id.au/
Bachelor of Computer Science and Technology II
University of Sydney

Re: [flask] Getting error when using request.method == post

From:
Rahul R
Date:
2010-06-06 @ 06:53
On Sun, Jun 6, 2010 at 9:51 AM, Peter Ward <peteraward@gmail.com> wrote:

> You might like to try running your application with debug mode on.
> Just change app.run() to app.run(debug=True).
> (obviously, you should disable this when you deploy your application)
>
> The problem is that "request is undefined", which is because you haven't
> imported it from the flask module.
> from flask import Flask, *request, *render_template
>
> Regards,
>   Peter
>
>
thanks Peter , i am not getting any errors but when i click submit ie ( http
POST ) the action was supposed to be navigation to another page
(loginpage.html in this case ) . But its rather static and not doing
anything.

Re: [flask] Getting error when using request.method == post

From:
Thadeus Burgess
Date:
2010-06-06 @ 07:10
With your logic it will not ever work, think about what you are doing.

You probably actually mean to do

if request.method == "POST":
   return dologin()

--
Thadeus





On Sun, Jun 6, 2010 at 1:53 AM, Rahul R <rahul8590@gmail.com> wrote:
>
>
> On Sun, Jun 6, 2010 at 9:51 AM, Peter Ward <peteraward@gmail.com> wrote:
>>
>> You might like to try running your application with debug mode on.
>> Just change app.run() to app.run(debug=True).
>> (obviously, you should disable this when you deploy your application)
>> The problem is that "request is undefined", which is because you haven't
>> imported it from the flask module.
>> from flask import Flask, request, render_template
>> Regards,
>>   Peter
>
> thanks Peter , i am not getting any errors but when i click submit ie ( http
> POST ) the action was supposed to be navigation to another page
> (loginpage.html in this case ) . But its rather static and not doing
> anything.
>

Re: [flask] Getting error when using request.method == post

From:
Rahul R
Date:
2010-06-06 @ 07:21
On Sun, Jun 6, 2010 at 11:10 AM, Thadeus Burgess <thadeusb@thadeusb.com>wrote:

> With your logic it will not ever work, think about what you are doing.
>
> You probably actually mean to do
>
> if request.method == "POST":
>   return dologin()
>
> --
> Thadeus
>
>
wow .. that was cake .... thanks a ton , i guess i gotto to peruse the
documentation.

Re: [flask] Getting error when using request.method == post

From:
Thadeus Burgess
Date:
2010-06-06 @ 07:30
Not much to do with flask.

Think about the logic.

This is what you were saying to the computer

"Ok, so if the request is of type POST, just run the dologin action
and then continue like a normal request"

This is because you were not returning the value of the function that
you called. You were effectively disposing the returned value of this
function by not assigning it to a variable or returning it.

What you really want is

"Ok so if the request is of type POST, then redirect them to the login action."

But your still saying

"Ok so if the request is of type POST, then render a different template".

So you take the return value of the function, and return that. This
effectively just renders a different template, it actually does NOT
redirect them.

If you want a true redirect...

return redirect(url_for('...'), code=302)

--
Thadeus





On Sun, Jun 6, 2010 at 2:21 AM, Rahul R <rahul8590@gmail.com> wrote:
>
>
> On Sun, Jun 6, 2010 at 11:10 AM, Thadeus Burgess <thadeusb@thadeusb.com>
> wrote:
>>
>> With your logic it will not ever work, think about what you are doing.
>>
>> You probably actually mean to do
>>
>> if request.method == "POST":
>>   return dologin()
>>
>> --
>> Thadeus
>>
>
> wow .. that was cake .... thanks a ton , i guess i gotto to peruse the
> documentation.
>

Re: [flask] Getting error when using request.method == post

From:
Rahul R
Date:
2010-06-06 @ 07:39
On Sun, Jun 6, 2010 at 11:30 AM, Thadeus Burgess <thadeusb@thadeusb.com>wrote:

> Not much to do with flask.
>
> Think about the logic.
>
> This is what you were saying to the computer
>
> "Ok, so if the request is of type POST, just run the dologin action
> and then continue like a normal request"
>
> This is because you were not returning the value of the function that
> you called. You were effectively disposing the returned value of this
> function by not assigning it to a variable or returning it.
>
> What you really want is
>
> "Ok so if the request is of type POST, then redirect them to the login
> action."
>
> But your still saying
>
> "Ok so if the request is of type POST, then render a different template".
>
> So you take the return value of the function, and return that. This
> effectively just renders a different template, it actually does NOT
> redirect them.
>
> If you want a true redirect...
>
> return redirect(url_for('...'), code=302)
>
> --
> Thadeus
>
> well

i wanted to naviagte to login action , which is wat i precisely did .
but how do i pass on the variable which are of form field of mine .
for example
in the hello page i accept username and password

<title>Hello from Flask</title>

  <h1>Hello rahul!</h1>
  <p> PLease fill in the details </p>

  <form action="" method="post">
            <p>username :<input type=text name=username>
            <p> password: <input type=text name=password>

			<p><input type=submit value=Login>
  </form>


so basically i have 2 variables username and password .
the user enters this and i navigate him to dologin function where a loginpage
is present.
but in the render template

	return render_template('loginpage.html')

i am only calling loginpage.html .

Is there any way where i can pass on the values of username and password
and finally print them in  the loginpage.html.