librelist archives

« back to archive

a very noob question

a very noob question

From:
Chengi Liu
Date:
2013-03-07 @ 04:14
Hi,

  I want to do something very simple..

I have a template with just one button...
And then when i click on that button,
I get a request a request in server that a button has been clicked.
Wait for few seconds..
and then display in the same an acknowledgement.

So something like
@app.route("/path", requests=['POST','GET']
def foobar():
    # wait for few seconds
    # and then something like
    #flash("request acknowledged??")

but i am not able to get my head around this.
any suggestions.
thanks

Re: [flask] a very noob question

From:
Oliver Song
Date:
2013-03-07 @ 04:20
You should probably just return a confirmation through the post request 
immediately, then call your wait to display the confirmation in 
javascript. It's generally not good to stall server side…


On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:

> Hi,
>  
>   I want to do something very simple..
>  
> I have a template with just one button...
> And then when i click on that button,
> I get a request a request in server that a button has been clicked.
> Wait for few seconds..
> and then display in the same an acknowledgement.
>  
> So something like  
> @app.route("/path", requests=['POST','GET']
> def foobar():
>     # wait for few seconds
>     # and then something like
>     #flash("request acknowledged??")
>   
> but i am not able to get my head around this.
> any suggestions.
> thanks
>  

Re: [flask] a very noob question

From:
Zaccardi, Nicholas
Date:
2013-03-07 @ 14:32
Are you asking how you would display the flash message on the web page?

Just trying to get a sense of what you are trying to do?

NZ

From: Chengi Liu <chengi.liu.86@gmail.com<mailto:chengi.liu.86@gmail.com>>
Reply-To: "flask@librelist.com<mailto:flask@librelist.com>" 
<flask@librelist.com<mailto:flask@librelist.com>>
Date: Thursday, March 7, 2013 4:11 AM
To: "flask@librelist.com<mailto:flask@librelist.com>" 
<flask@librelist.com<mailto:flask@librelist.com>>
Subject: Re: [flask] a very noob question

Hi,
 How can I send the confirmation from server...
What will my template and view look like?


On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song 
<osong@mit.edu<mailto:osong@mit.edu>> wrote:
You should probably just return a confirmation through the post request 
immediately, then call your wait to display the confirmation in 
javascript. It's generally not good to stall server side…

On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:

Hi,

  I want to do something very simple..

I have a template with just one button...
And then when i click on that button,
I get a request a request in server that a button has been clicked.
Wait for few seconds..
and then display in the same an acknowledgement.

So something like
@app.route("/path", requests=['POST','GET']
def foobar():
    # wait for few seconds
    # and then something like
    #flash("request acknowledged??")

but i am not able to get my head around this.
any suggestions.
thanks


Re: [flask] a very noob question

From:
Chengi Liu
Date:
2013-03-07 @ 10:11
Hi,
 How can I send the confirmation from server...
What will my template and view look like?


On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song <osong@mit.edu> wrote:

>  You should probably just return a confirmation through the post request
> immediately, then call your wait to display the confirmation in javascript.
> It's generally not good to stall server side…
>
> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>
> Hi,
>
>   I want to do something very simple..
>
> I have a template with just one button...
> And then when i click on that button,
> I get a request a request in server that a button has been clicked.
> Wait for few seconds..
> and then display in the same an acknowledgement.
>
> So something like
> @app.route("/path", requests=['POST','GET']
> def foobar():
>     # wait for few seconds
>     # and then something like
>     #flash("request acknowledged??")
>
> but i am not able to get my head around this.
> any suggestions.
> thanks
>
>
>

Re: [flask] a very noob question

From:
Owein Reese
Date:
2013-03-07 @ 12:34
@app.route('/myroute')
def mypost():
  return "got it"

That will return a 200. Alternatively you could use the Response object.
On Mar 7, 2013 5:12 AM, "Chengi Liu" <chengi.liu.86@gmail.com> wrote:

> Hi,
>  How can I send the confirmation from server...
> What will my template and view look like?
>
>
> On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song <osong@mit.edu> wrote:
>
>>  You should probably just return a confirmation through the post request
>> immediately, then call your wait to display the confirmation in javascript.
>> It's generally not good to stall server side…
>>
>> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>>
>> Hi,
>>
>>   I want to do something very simple..
>>
>> I have a template with just one button...
>> And then when i click on that button,
>>  I get a request a request in server that a button has been clicked.
>> Wait for few seconds..
>> and then display in the same an acknowledgement.
>>
>> So something like
>> @app.route("/path", requests=['POST','GET']
>> def foobar():
>>     # wait for few seconds
>>     # and then something like
>>     #flash("request acknowledged??")
>>
>> but i am not able to get my head around this.
>> any suggestions.
>> thanks
>>
>>
>>
>

Re: [flask] a very noob question

From:
Chengi Liu
Date:
2013-03-07 @ 16:34
Ok. this will be probably a javascript question

@app.route('/myroute')
def mypost():
  return "got it"

what would my template look like.
So what i am trying to get at is..
user clicks a button.. server responds.. and while we get the response..
i display something like:
Your request is being processed animation..
I have found this issue here :

http://stackoverflow.com/questions/15264477/refresh-animation-and-then-redirect-to-differnt-url/15264600?noredirect=1#comment21531654_15264600
but i dont know how to tie this up with flask.



On Thu, Mar 7, 2013 at 4:34 AM, Owein Reese <owreese@gmail.com> wrote:

> @app.route('/myroute')
> def mypost():
>   return "got it"
>
> That will return a 200. Alternatively you could use the Response object.
> On Mar 7, 2013 5:12 AM, "Chengi Liu" <chengi.liu.86@gmail.com> wrote:
>
>> Hi,
>>  How can I send the confirmation from server...
>> What will my template and view look like?
>>
>>
>> On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song <osong@mit.edu> wrote:
>>
>>>  You should probably just return a confirmation through the post request
>>> immediately, then call your wait to display the confirmation in javascript.
>>> It's generally not good to stall server side…
>>>
>>> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>>>
>>> Hi,
>>>
>>>   I want to do something very simple..
>>>
>>> I have a template with just one button...
>>> And then when i click on that button,
>>>  I get a request a request in server that a button has been clicked.
>>> Wait for few seconds..
>>> and then display in the same an acknowledgement.
>>>
>>> So something like
>>> @app.route("/path", requests=['POST','GET']
>>> def foobar():
>>>     # wait for few seconds
>>>     # and then something like
>>>     #flash("request acknowledged??")
>>>
>>> but i am not able to get my head around this.
>>> any suggestions.
>>> thanks
>>>
>>>
>>>
>>

Re: [flask] a very noob question

From:
Smartboy
Date:
2013-03-07 @ 16:51
You should probably return status code 202 from /myroute (maybe along with
an ID), which is the HTTP status code saying it's processing but not yet
completed. Then you can poll another url with the ID given from the last
route, and it will either return 202 again (still processing) or 204
(status code for successfully completed but no content) if it completed.
You can do that through javascript by using the setTimeout function to run
a polling function periodically after the 202 and ID was returned from
/myroute. To do this with flask, you'd have something like:

@app.route('/myroute')
def myroute():
    # submit for processing and generate an ID, lets say abcdefg
    return Response(status=202, response="{id: abcdefg}",
mimetype="application/json")

@app.route('/myroute/<job_id>')
def myroute(job_id):
    if still_processing(job_id):
        return Response(status=202)
    elif is_completed(job_id):
        return Response(status=204)
    else:
        return Response(status=404)

However, this does require a separate process to submit jobs to, though
something like Celery could help with this if you don't already have a job
server created.

Hope this helps a bit,
Smartboy

On Thu, Mar 7, 2013 at 8:34 AM, Chengi Liu <chengi.liu.86@gmail.com> wrote:

> Ok. this will be probably a javascript question
>
> @app.route('/myroute')
> def mypost():
>   return "got it"
>
> what would my template look like.
> So what i am trying to get at is..
> user clicks a button.. server responds.. and while we get the response..
> i display something like:
> Your request is being processed animation..
> I have found this issue here :
> 
http://stackoverflow.com/questions/15264477/refresh-animation-and-then-redirect-to-differnt-url/15264600?noredirect=1#comment21531654_15264600
> but i dont know how to tie this up with flask.
>
>
>
> On Thu, Mar 7, 2013 at 4:34 AM, Owein Reese <owreese@gmail.com> wrote:
>
>> @app.route('/myroute')
>> def mypost():
>>   return "got it"
>>
>> That will return a 200. Alternatively you could use the Response object.
>> On Mar 7, 2013 5:12 AM, "Chengi Liu" <chengi.liu.86@gmail.com> wrote:
>>
>>> Hi,
>>>  How can I send the confirmation from server...
>>> What will my template and view look like?
>>>
>>>
>>> On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song <osong@mit.edu> wrote:
>>>
>>>>  You should probably just return a confirmation through the post
>>>> request immediately, then call your wait to display the confirmation in
>>>> javascript. It's generally not good to stall server side…
>>>>
>>>> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>>>>
>>>> Hi,
>>>>
>>>>   I want to do something very simple..
>>>>
>>>> I have a template with just one button...
>>>> And then when i click on that button,
>>>>  I get a request a request in server that a button has been clicked.
>>>> Wait for few seconds..
>>>> and then display in the same an acknowledgement.
>>>>
>>>> So something like
>>>> @app.route("/path", requests=['POST','GET']
>>>> def foobar():
>>>>     # wait for few seconds
>>>>     # and then something like
>>>>     #flash("request acknowledged??")
>>>>
>>>> but i am not able to get my head around this.
>>>> any suggestions.
>>>> thanks
>>>>
>>>>
>>>>
>>>
>

Re: [flask] a very noob question

From:
Anthony Ford
Date:
2013-03-07 @ 17:00
I'd say unless you want to spend time making a custom rendering, just use a
spinning gif (http://preloaders.net/), then make an ajax call back to
whatever process you are running (or rather, an endpoint that can check on
the execution of that process).

I.E:

1. User Clicks on submit (headed to /process for example)
2. endpoint /process gives them a page with a loading gif and an ajax
request that checks /status
3. if /status responds that the request is complete, it replaces the gif
with a message that says the process is complete


you can use some simple queue system to run processes outside the app, to
prevent blocking. There's discussions on the list regarding different queue
systems.

Anthony Ford,
KF5IBN,
Research Assistant,
Center for Advanced Radio Astronomy,
University of Texas at Brownsville
ford.anthonyj@gmail.com


On Thu, Mar 7, 2013 at 10:34 AM, Chengi Liu <chengi.liu.86@gmail.com> wrote:

> Ok. this will be probably a javascript question
>
> @app.route('/myroute')
> def mypost():
>   return "got it"
>
> what would my template look like.
> So what i am trying to get at is..
> user clicks a button.. server responds.. and while we get the response..
> i display something like:
> Your request is being processed animation..
> I have found this issue here :
> 
http://stackoverflow.com/questions/15264477/refresh-animation-and-then-redirect-to-differnt-url/15264600?noredirect=1#comment21531654_15264600
> but i dont know how to tie this up with flask.
>
>
>
>  On Thu, Mar 7, 2013 at 4:34 AM, Owein Reese <owreese@gmail.com> wrote:
>
>> @app.route('/myroute')
>> def mypost():
>>   return "got it"
>>
>> That will return a 200. Alternatively you could use the Response object.
>> On Mar 7, 2013 5:12 AM, "Chengi Liu" <chengi.liu.86@gmail.com> wrote:
>>
>>> Hi,
>>>  How can I send the confirmation from server...
>>> What will my template and view look like?
>>>
>>>
>>> On Wed, Mar 6, 2013 at 8:20 PM, Oliver Song <osong@mit.edu> wrote:
>>>
>>>>  You should probably just return a confirmation through the post
>>>> request immediately, then call your wait to display the confirmation in
>>>> javascript. It's generally not good to stall server side…
>>>>
>>>> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>>>>
>>>> Hi,
>>>>
>>>>   I want to do something very simple..
>>>>
>>>> I have a template with just one button...
>>>> And then when i click on that button,
>>>>  I get a request a request in server that a button has been clicked.
>>>> Wait for few seconds..
>>>> and then display in the same an acknowledgement.
>>>>
>>>> So something like
>>>> @app.route("/path", requests=['POST','GET']
>>>> def foobar():
>>>>     # wait for few seconds
>>>>     # and then something like
>>>>     #flash("request acknowledged??")
>>>>
>>>> but i am not able to get my head around this.
>>>> any suggestions.
>>>> thanks
>>>>
>>>>
>>>>
>>>
>

Re: [flask] a very noob question

From:
Zaccardi, Nicholas
Date:
2013-03-07 @ 04:23
Completely agree.  Sounds like something for JS.

However, if are set in your ways, checkout time.sleep()  That might do 
what you want it too.

NZ

From: Oliver Song <osong@mit.edu<mailto:osong@mit.edu>>
Reply-To: "flask@librelist.com<mailto:flask@librelist.com>" 
<flask@librelist.com<mailto:flask@librelist.com>>
Date: Wednesday, March 6, 2013 10:20 PM
To: "flask@librelist.com<mailto:flask@librelist.com>" 
<flask@librelist.com<mailto:flask@librelist.com>>
Subject: Re: [flask] a very noob question

You should probably just return a confirmation through the post request 
immediately, then call your wait to display the confirmation in 
javascript. It's generally not good to stall server side…

On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:

Hi,

  I want to do something very simple..

I have a template with just one button...
And then when i click on that button,
I get a request a request in server that a button has been clicked.
Wait for few seconds..
and then display in the same an acknowledgement.

So something like
@app.route("/path", requests=['POST','GET']
def foobar():
    # wait for few seconds
    # and then something like
    #flash("request acknowledged??")

but i am not able to get my head around this.
any suggestions.
thanks

Re: [flask] a very noob question

From:
孔令超
Date:
2013-03-07 @ 04:30
from time import sleep
sleep(5)
flash('....')

why do so?

or

$.ajax({
url:'...',
sucess:function(data){
setTimeout(...);
}
});

2013/3/7 Oliver Song <osong@mit.edu>

>  You should probably just return a confirmation through the post request
> immediately, then call your wait to display the confirmation in javascript.
> It's generally not good to stall server side…
>
> On Wednesday, March 6, 2013 at 11:14 PM, Chengi Liu wrote:
>
> Hi,
>
>   I want to do something very simple..
>
> I have a template with just one button...
> And then when i click on that button,
>  I get a request a request in server that a button has been clicked.
> Wait for few seconds..
> and then display in the same an acknowledgement.
>
> So something like
> @app.route("/path", requests=['POST','GET']
> def foobar():
>     # wait for few seconds
>     # and then something like
>     #flash("request acknowledged??")
>
> but i am not able to get my head around this.
> any suggestions.
> thanks
>
>
>


-- 
发送自孔令超

Re: [flask] a very noob question

From:
Steven Kryskalla
Date:
2013-03-07 @ 04:24
On Wed, Mar 6, 2013 at 8:14 PM, Chengi Liu <chengi.liu.86@gmail.com> wrote:
> I have a template with just one button...
> And then when i click on that button,
> I get a request a request in server that a button has been clicked.
> Wait for few seconds..
> and then display in the same an acknowledgement.

You probably want to use javascript and AJAX to do that. There are
many tutorials and pages on the internet for doing AJAX. Here's one
from the first page of a google search (using jquery, a library that
makes ajax easier, among other things):

http://stackoverflow.com/questions/9436534/ajax-tutorial-for-post-and-get

-Steve