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.