Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19191 > unrolled thread

What's the very simplest way to run some Python from a button on a web page?

Started bytinnews@isbd.co.uk
First post2012-01-21 14:58 +0000
Last post2012-01-22 10:04 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  What's the very simplest way to run some Python from a button on a web page? tinnews@isbd.co.uk - 2012-01-21 14:58 +0000
    Re: What's the very simplest way to run some Python from a button on a web page? Tim Roberts <timr@probo.com> - 2012-01-21 20:36 -0800
      Re: What's the very simplest way to run some Python from a button on a web page? Chris Angelico <rosuav@gmail.com> - 2012-01-22 15:52 +1100
        Re: What's the very simplest way to run some Python from a button on a web page? tinnews@isbd.co.uk - 2012-01-22 10:05 +0000
      Re: What's the very simplest way to run some Python from a button on a web page? tinnews@isbd.co.uk - 2012-01-22 10:04 +0000

#19191 — What's the very simplest way to run some Python from a button on a web page?

Fromtinnews@isbd.co.uk
Date2012-01-21 14:58 +0000
SubjectWhat's the very simplest way to run some Python from a button on a web page?
Message-ID<vd0ru8-mip.ln1@chris.zbmc.eu>
I want to run a server side python script when a button on a web page
is clicked.  This is on a LAMP server - apache2 on xubuntu 11.10.

I know I *could* run it as a CGI script but I don't want to change the
web page at all when the button is clicked (I'll see the effect
elsewhere on the screen anyway) so normal CGI isn't ideal.

It's easy to show a button:-

    <INPUT TYPE=submit NAME="Button" ONCLICK=something>;

Can I get away with something clever for 'something' that will somehow
hook through to a server side script?

Alternatively, seeing as both client and server are on the same
system, this *could* be done on the client side by breaking out of the
browser sandbox - is there any easy way to do this?


I'm just looking for the crudest, simplest possible way of doing this,
it's only for my own convenience to fire up a utility I want to use
when viewing certain of my local HTML pages.  These pages aren't
visible from the outside world so security isn't a big issue.

-- 
Chris Green

[toc] | [next] | [standalone]


#19200

FromTim Roberts <timr@probo.com>
Date2012-01-21 20:36 -0800
Message-ID<q84nh7hoa3lolbcc2fnqu47jh69bng0els@4ax.com>
In reply to#19191
tinnews@isbd.co.uk wrote:
>
>I want to run a server side python script when a button on a web page
>is clicked.  This is on a LAMP server - apache2 on xubuntu 11.10.
>
>I know I *could* run it as a CGI script but I don't want to change the
>web page at all when the button is clicked (I'll see the effect
>elsewhere on the screen anyway) so normal CGI isn't ideal.

It seems what you're after is AJAX.  If you are using a Javascript
framework like jQuery, it's easy to fire off an asynchronous request back
to your server that leaves the existing page alone.  If you aren't, then I
think the easiest method is to use an invisible <iframe>.  From Javascript,
you can set the "src" property of the <iframe> to fire off a request while
leaving the rest of the page alone.

You could spend the rest of your career reading all of the good web
material on AJAX.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

[toc] | [prev] | [next] | [standalone]


#19201

FromChris Angelico <rosuav@gmail.com>
Date2012-01-22 15:52 +1100
Message-ID<mailman.4918.1327207947.27778.python-list@python.org>
In reply to#19200
On Sun, Jan 22, 2012 at 3:36 PM, Tim Roberts <timr@probo.com> wrote:
> It seems what you're after is AJAX.  If you are using a Javascript
> framework like jQuery, it's easy to fire off an asynchronous request back
> to your server that leaves the existing page alone.

If you aren't using a framework, look up the XMLHttpRequest object -
that's what does the work. As Tim says, there's no lack of good
material on the subject.

ChrisA

[toc] | [prev] | [next] | [standalone]


#19209

Fromtinnews@isbd.co.uk
Date2012-01-22 10:05 +0000
Message-ID<kj3tu8-r6q.ln1@chris.zbmc.eu>
In reply to#19201
Chris Angelico <rosuav@gmail.com> wrote:
> On Sun, Jan 22, 2012 at 3:36 PM, Tim Roberts <timr@probo.com> wrote:
> > It seems what you're after is AJAX.  If you are using a Javascript
> > framework like jQuery, it's easy to fire off an asynchronous request back
> > to your server that leaves the existing page alone.
> 
> If you aren't using a framework, look up the XMLHttpRequest object -
> that's what does the work. As Tim says, there's no lack of good
> material on the subject.
> 
OK, thanks both, with those pointers I think I'm on the way.

-- 
Chris Green

[toc] | [prev] | [next] | [standalone]


#19210

Fromtinnews@isbd.co.uk
Date2012-01-22 10:04 +0000
Message-ID<nh3tu8-r6q.ln1@chris.zbmc.eu>
In reply to#19200
Tim Roberts <timr@probo.com> wrote:
> tinnews@isbd.co.uk wrote:
> >
> >I want to run a server side python script when a button on a web page
> >is clicked.  This is on a LAMP server - apache2 on xubuntu 11.10.
> >
> >I know I *could* run it as a CGI script but I don't want to change the
> >web page at all when the button is clicked (I'll see the effect
> >elsewhere on the screen anyway) so normal CGI isn't ideal.
> 
> It seems what you're after is AJAX.  If you are using a Javascript
> framework like jQuery, it's easy to fire off an asynchronous request back
> to your server that leaves the existing page alone.  If you aren't, then I
> think the easiest method is to use an invisible <iframe>.  From Javascript,
> you can set the "src" property of the <iframe> to fire off a request while
> leaving the rest of the page alone.
> 
OK, thanks, I'd sort of found that the answer seems to be AJAX but now
you have confirmed it I'll start looking harder.


> You could spend the rest of your career reading all of the good web
> material on AJAX.

:-)

-- 
Chris Green

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web