librelist archives

« back to archive

javascript , jinja2 , routing problem of a noob

javascript , jinja2 , routing problem of a noob

From:
Edgar Almonte
Date:
2012-04-25 @ 18:02
hello

a total noob guys here trying to learn a bit about programing and html ,
now i do a little webinterfase for a radio scanner using cherrypy but i
never finish it , just go working the part that send some command to the
radio scanner , the thing is i am now trying to complete it and using flask
instead of cherrypy

here the old code:
https://github.com/e0x/webremote_pro_2052

in this code i have a javascript part that create a function for do a http
request to a url that was a function in the python/cherrypy/server side


<script>
function invokeCmd(param) {
  var http = new XMLHttpRequest();
  http.open("GET", "http://r00t-ed.homeip.net/~e0x/runcmd?Button=" + param,
true);

  http.send(null);
  http.send(null);
  http.onreadystatechange = function()
{
   if(this.readyState == 4 && this.status == 200)
     {
     document.getElementById('freq').value = this.responseText;
     }
}
http.open("GET", "/runcmd?Button=" + param, true);
http.send(null);
}
</script>

then in the buttons in the interfase i do example:

            <input type="button" name="Skip" value="Skip"
              OnClick="javascript:invokeCmd('KEY06')"/>

now like i say i am trying do this using flask but not sure how define the
function in the python side that handle the paramenter i am pass to it.

right now i generate the url i do the same i was doing in the old version
but when i do the request i get a 404 error


thanks.

Re: [flask] javascript , jinja2 , routing problem of a noob

From:
Simon Sapin
Date:
2012-04-27 @ 09:35
Le 25/04/2012 20:02, Edgar Almonte a écrit :
> now like i say i am trying do this using flask but not sure how define
> the function in the python side that handle the paramenter i am pass to it.
>
> right now i generate the url i do the same i was doing in the old
> version but when i do the request i get a 404 error

Hi,

The parameters that you pass after '?' are in request.args
(Use 'from flask import request' to get the request object.)

http://flask.pocoo.org/docs/api/#flask.Request.args

Other than that, Quickstart and Tutorial part of the documentation can 
probably help you:

http://flask.pocoo.org/docs/

Regards,
-- 
Simon Sapin

Re: [flask] javascript , jinja2 , routing problem of a noob

From:
Edgar Almonte
Date:
2012-04-27 @ 12:02
Thanks , i will check that

On Fri, Apr 27, 2012 at 5:35 AM, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 25/04/2012 20:02, Edgar Almonte a écrit :
> > now like i say i am trying do this using flask but not sure how define
> > the function in the python side that handle the paramenter i am pass to
> it.
> >
> > right now i generate the url i do the same i was doing in the old
> > version but when i do the request i get a 404 error
>
> Hi,
>
> The parameters that you pass after '?' are in request.args
> (Use 'from flask import request' to get the request object.)
>
> http://flask.pocoo.org/docs/api/#flask.Request.args
>
> Other than that, Quickstart and Tutorial part of the documentation can
> probably help you:
>
> http://flask.pocoo.org/docs/
>
> Regards,
> --
> Simon Sapin
>