Server side newbie

S

swisscheese

I have a simple python desktop app with several edit controls and a
couple of buttons. It just does some math. What's the simplest way to
make it a server-side app so visitors to my site can run the app via
their browser?
 
D

Dave

Check out mod_python for Apache. Basically, you would write your python
app as a server-side script and the end user would interact with your
code via a webpage. It's likely that you won't need any GUI code you
wrote, as HTML form elements will be your choices in the browser.

Check out PSP: it enables you to mix Python code with an otherwise
ordinary HTML page.

Mod_Python:
http://www.modpython.org/

PSP article:
http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html
 
P

Peter Hansen

swisscheese said:
I have a simple python desktop app with several edit controls and a
couple of buttons. It just does some math. What's the simplest way to
make it a server-side app so visitors to my site can run the app via
their browser?

There will probably be a dozen answers, any of which might meet whatever
subjective way you have of judging "simplicity", but here's one:

1. strip the GUI code off
2. wrap the remaining core with a simple CGI interface
2. make a web form in HTML that calls it

-Peter
 
P

Pierre Quentel

swisscheese a écrit :
I have a simple python desktop app with several edit controls and a
couple of buttons. It just does some math. What's the simplest way to
make it a server-side app so visitors to my site can run the app via
their browser?
Among the many web frameworks for Python, Karrigell is probably the
easiest to get started with

You can check out a recent review on devshed :
http://www.devshed.com/c/a/Python/Karrigell-for-Python/

It says : "Python novices won't find any obstacles when working with
Karrigell, and Python experts won't feel too limited"

Regards,
Pierre
 
J

John M. Gabriele

swisscheese said:
I have a simple python desktop app with several edit controls and a
couple of buttons. It just does some math. What's the simplest way to
make it a server-side app so visitors to my site can run the app via
their browser?

The *simplest* way is to make it into a CGI script.

What you'll probably want is to make the CGI script
produce some html with a form in it. The form action
is the CGI script itself. This way, after you hit the
submit button, you get the same page back again (with
your math answer written in the page somewhere), with
the same fields and submit button waiting for you to
use the script again.

Use the cgi module to access the data that gets
submitted by the form.

To run your script, you'll need to install a web server.
On Debian it's:

apt-get install apache2

Then you put your CGI script into /usr/lib/cgi-bin/foo.py
and point your browser to

http://localhost/cgi-bin/foo.py

---J
 
J

jimlewis

Thanks for the various replies. They all seem to lead to a lot more
learning. I thought Python was supposed to make it easy to build web
apps. It appears after going thru the learning curve for Python I need
to learn unix, a framework, brush up on HTML and so on. It's like being
caught in a spider web of web sites with endless tools. And the sites
assume everyone knows the lingo - just connect the cgi to the
mod_python and install to apache setting the path to ... - sure.
Someone should invent a way to automate all this. My python app fully
describes the UI and behaviour so it seems possible. Or at least the
sites should learn how to write to a broader audience so they can be
understood by newbies. Here's hoping for an easier future :)
 
P

Paul Rubin

Someone should invent a way to automate all this. My python app fully
describes the UI and behaviour so it seems possible. Or at least the
sites should learn how to write to a broader audience so they can be
understood by newbies. Here's hoping for an easier future

There has been some discussion about settling on a standard web
framework to include in the standard Python distro. That will make
things easier. However, right now, things are not in a settled enough
technical state to make such a move.

You might look at PHP, which has an built-in html template system and
generally more complete web server integration than Python currently
has. Some people write PHP front ends for Python apps, communicating
through XML or some other method. You will have to learn some basic
HTML no matter what. Philip and Alex's Guide to Web Publishing is an
old but maybe still worthwhile book on how server side web programming
(specifically database backed site development) works. Full text online:

http://philip.greenspun.com/panda/
 
P

Peter Hansen

Thanks for the various replies. They all seem to lead to a lot more
learning. I thought Python was supposed to make it easy to build web
apps. It appears after going thru the learning curve for Python I need
to learn unix, a framework, brush up on HTML and so on. It's like being
caught in a spider web of web sites with endless tools. And the sites
assume everyone knows the lingo - just connect the cgi to the
mod_python and install to apache setting the path to ... - sure.
Someone should invent a way to automate all this. My python app fully
describes the UI and behaviour so it seems possible.

The problem is more the web's than Python's though Python _could_ have
significant additions that would overcome the hurdle. You are correct
that given the current state of affairs you can't just magically make a
GUI program show up on the web effectively. There are a wide range of
technical reasons for that, most of which have nothing whatsoever to do
with Python. Most any other language would be the same (though there
may in fact be one or two special cases where this magic
interoperability is supported... might be interesting to hear of them).

Also, just as writing a GUI with Python requires some basic knowledge of
GUI programming, hooking anything interesting to the web requires a
basic knowledge of some web stuff. Not mod_python, certainly, and
technically you don't need to know anything about apache either, but
even if you took a more direct route, there are two inescapable facts
that will block you given your apparent current level of knowledge.

One is that you pretty much have to know about HTML at some level to be
able to generate dynamic output for web clients. (Even if you use a
canned framework to do the grunt work, it's unlikely you'd be able to
use it effectively without understanding what it was doing under the
covers.)

Secondly, you'd need to know how to get a basic web server set up and
available through your ISP. Whether that involves running something on
your own computer and using a dynamic DNS service, or installing
something that will run in whatever non-standard environment your own
ISP provides, or something else, is a question we can't answer. (At
least, without more background, and you provided none that is useful in
your first posting, just the vague "my site" which means nothing to us.)

Regardless, you are certainly correct about a number of things. One is
that more learning is required. Does that really surprise you? Another
is that this _could_ largely be automated, though not for all possible
GUI features (and certainly not when you haven't even told us which GUI
framework you used), as the web and standard GUIs have an incompatible
architecture. The final result, most likely, would be much easier than
what exists now, but there's a good chance *you* would still have gotten
to the same roadblock, since you wrote your program first and only
*then* asked "how do I hook this to the web?". Generally, if you
haven't planned properly in advance, you'll find yourself stuck with
more learning and more work when you come to the next requirement in the
list.

-Peter
 
J

jimlewis

Thanks for the comments. I do know basic HTML although it seems like
writing in assembly language. Filling in the blanks you outlined: my
ISP is pair.com and they show python as available. My site is
quirkle.com. True I did not think much about hooking my app to the web
but I had, I think, a reasonably justified impression that python
helped make it easy to develop web apps.
 
P

Peter Hansen

Thanks for the comments. I do know basic HTML although it seems like
writing in assembly language. Filling in the blanks you outlined: my
ISP is pair.com and they show python as available. My site is
quirkle.com. True I did not think much about hooking my app to the web
but I had, I think, a reasonably justified impression that python
helped make it easy to develop web apps.

Python _does_ make it easy to develop web apps, though it doesn't make
it so easy that you can get away without knowing some of the ugly
details about the web.

Given that you've got a handle on GUI programming, with the right
framework you might not have that much trouble doing web stuff either.
One thing that might be of help is this page
http://pyre.third-bit.com/pyweb/index.html which compares in some detail
several of the more popular frameworks. The page at
http://wiki.python.org/moin/WebProgramming provides a possibly
exhaustive list of the existing frameworks. The diversity shown there
is certainly related to the fact that the world hasn't yet figured out
how to make all kinds of web programming quite as standardized as GUI
programming has become.

I can't recommend a solution that I know would work for you, but I can
suggest you consider starting by looking at CherryPy (mentioned on both
the above), as a fairly self-contained and straightforward approach to
doing web work in Python. If you can adapt your GUI structure to the
web, CherryPy should let you implement it fairly easily and quickly,
though it is not intended to do everything for you but rather to make it
simple to do the fundamental things that web servers still need to do.

-Peter
 
J

jimlewis

Can you point me to sample code somewhere? If I had a server-side
python script that increments the number in an edit control on clicking
a button, I think I could take it from there.
 
P

Paul Rubin

Can you point me to sample code somewhere? If I had a server-side
python script that increments the number in an edit control on clicking
a button, I think I could take it from there.

Oh man, I hate to say this since it's not a good situation, but what
you're asking is a little bit more complicated than I think you're
expecting. You need a server app with some notion of sessions (I
assume the user is supposed to be able to increment the number more
than once), so you have to know a bit about how servers and HTTP work,
plus how to write HTML, in addition to Python and some suitable server
side modules.

Your best bet might be to use a web framework that already understands
sessions, but 1) you have to decide which one to use, since there are
several to choose from with differing sets of features; and 2) these
frameworks are designed for writing complex apps, so learning them may
be a bit much for something this simple. But if your idea is to build
towards a real web app that does something more serious, then a
framework is the way to go.

There's an old book about how database-backed web sites work, that
is pretty long, but well written. It's online:
http://philip.greenspun.com/panda
 
R

Ravi Teja

swisscheese said:
I have a simple python desktop app with several edit controls and a
couple of buttons. It just does some math. What's the simplest way to
make it a server-side app so visitors to my site can run the app via
their browser?

If the math is simple, you can just use JavaScript. No need to bother
running it on the server.
 
J

jimlewis

Thanks but the math is a bit complex and already coded and debugged in
a python desktop gui.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top