[Tutor] web-based python?

Alan Gauld alan.gauld at btinternet.com
Mon Aug 2 02:10:54 CEST 2010

"Che M" <pine508 at hotmail.com> wrote
> For a long time I have hoped for a "Python web apps for absolute 
> beginners"
> ....  I just checked Alan Gauld's Learning to Program and was 
> disappointed
> to see the section on writing web apps hasn't been done yet,

I started on the client side topic but then Python 3 came out and I've
been diverted rewriting everything for that. I'm hoping to get the v3 
up to the same place as the v2 one by the end of the year - then maybe
I'll get round to finishing the web programming section.

However I will only be covering basic CGI scripting, I don't intend to 
any of the Frameworks. Mainly becauase moast of them have perfectly
good tutorials already once you understand the bare bones of CGI.

> - What the the various kinds of web apps one can make are and (very) 
> roughly
>   how much work each entails.  In other words, there is a difference 
> between
>   writing an online newspaper vs. a web based GUI app.

Actually web apps are all pretty similar. They consist of three basic 
(maybe 4):
1) A mechanism for mapping a URL to a Python function or method.
2) A mechanism for generating HTML with embedded data values
3) A data storage mechanism
4) Some client code for a more dynamic feel

What they look like is just down to HTML creativity. But they all 
out as an HTML web page with some kind of form that captures data.
When you submit the form yyou send some data to the server which
interprets it and generates a new HTML page back again. There might
be some flash graphics or some Javascript doing clever display stuff
to make tings more dynamic, but basically all web apps work by
capturing some data and sending it to a server which generates a
new page in response.

In fact designing a web app is a lot like designing an old fashioned
mainframe terminal application. They also worked on a page view basis
albeit a 24linex80character display page...

> - Whether it matters if you develop on Windows, Linux, or Mac.

The whole point of the web is that it doersn'ty care. You can write 
specific web code - especially on Microsoft platforms - but all that 
is limits your audience. There is no good reason to do it.

> - The easiest possible "Hello, World!" (just text) in a web browser.

<html><body><p>Hello, World!</body></html>

That's it as a one liner.

If you want it as a CGI program in Python its only slightly longer
and the CGI documentation shows you how...

> - How much of other languages (XHTML, CSS, Javascript, etc.) you 
> need to know.

That all depends on how fancy you want the presentation to be.
For professional standard you will definitely need all 3.
For basic stuff HTML is all you really need.

> - What you need to understand about servers and how to communicate 
> with them.

Not a lot if you use a Framework, but debugging problems is easier
if you understand whats actually happening.

> - How you can get more than just text on a web app, that is, 
> widgets, and
>   therefore what are currently the options for that (learning 
> javascript and whatever
>   widget toolkits are out there for that; qooxdoo; Pyjamas; others).

This is where it gets very complicated. There are lots of different 
ways of
doing widgets (in out company we have a "standard" that defines 4 
or kinds, of widget you can build and still be complant with the 
architecture! The simplest is an IFrame fragment)

> - Whether you could use Pyjamas to make your code work
> as both a web app and a desktop app.

I've heard of pyjamas but not used it. The .NET framework has a 
concept but in my experience the results are usually not very good 
and not very good web apps... Its better to design for one or the 
and do a good job for that one.

> - How you can develop your web app on your own computer and when you
>   need to test it actually on the web.

Thats usually just a case of running a web server on your PC.
There are many to choose from and Python even offers a couple in the
standard library.

> - What to consider when choosing a way to host your app online.
> - How to get your Python code onto that server, as well as whatever 
> other
>   code (like Django) there too. (Alex's question)

ftp is the usual way.

> - Why starting with a MVC pattern may be the best way to go for a 
> web app.

MVC is usually the best pattern for any UI centric app, whether 
client/server or web. It maximises reuse and clarifies the logic.

> - What you need to consider to make your web app work the same
> on most browsers.

Stick to established standards and remember that by its nature the web
does not give you fine control. So design the GUI in the knowledge 
different browsers will do different things with it and that is their 
right - and
that of your user. Then realise that this will invariably compromise 
user experienve. So you then decide whether maximum reach or maximum
user satisfaction is most important to you.

> - Scalability issues, speed issues, Security issues, cost issues; 
> etc.

Pretty much the same as for any server application.

> - What databases to use and why

Pretty much web independant.

> - Issues concerning whether your app can be used by iPhones
> and other smart phones.

Yes, this is becoming a real issue. I've no real experience to offer
on this one yet.

> - Opening your code to contribution; monetizing your service

Again not really web specific.

> - Probably lots of other stuff I don't even know about.

Probably :-)

> I understand much of this is about web apps generally
> and is not germane only to Python,

Thats true of any general programming paradigm like GUI or database
programming. There just happens to be some Python libraries stuck
on top thats all.

> but it would be good if a Python tutorial at least pointed toward
> this information, since for many beginners, the entry portal to
> anything is through Python.

Wikipedia is your friend and the partial topic that I did on web
programming did include some of the basic stuff with lots of
links to Wikipedia articles.

You can find it on the v2 tutor under writing web clients, but
its very draft and incomplete...


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list