Using Python for my web site

Luis M. González luismgz at gmail.com
Tue Aug 1 01:25:02 EDT 2006


I don't have experience with Django or any other python framework, but
I have used bare-bones mod_python and it rocks.
I wouldn't use PSP though...
It is not very polished, and they way it handles the "indentation
problem" in python is a little bit confussing.

IMHO the best way of using mod_python is with its publisher handler.
It let's you code your applications in a MVC (model view controller)
style.
This way you can cleanly separate presentation and logic, making your
code more concise, clear and mantainable.

With publisher, every function defined in your script represents a web
page in your site, and the html code can be moved to a template, that
could be PSP itself or Cheetah, for example (Cheetah is very good).

A very simple example:

#mysite.py

def index(req):
    req.content_type = 'text/html'
    req.write("""
    <form action = mysite.py/printMyName method = post>
    <input type = text name = myname>
    <input type = submit>
    """)

def printMyName(req, myname):
    req.content_type = 'text/html'
    req.write(myname)

# end of mysite.py

In this script, the function "index" is executed by default when you go
to http://yourserver/mysite.py, and it displays a text box and a submit
button.
(The first line indicates that the output will be in html format, and
"req.write" is equivalent to "print".)

If you enter your name and hit the submit button, your name is passed
to the "printMyName" function and printed in your browser's screen.

This way, both functions can be viewed like two separate pages within
your site.
So, with only one script, you can write a whole site if you want.

For more complex pages where html is used, you can place this
presentation code in templates, and then import them into your main
script.
Or else, you could simple use "req.write" to print your html directly
(as I did in "index").
Hope this helps...

Luis







northband wrote:
> Hi, I am interested in re-writing my website in Python vs PHP but have
> a few questions. Here are my specs, please advise as to which
> configuration would be best:
>
> 1.Dell Poweredge Server, w/IIS, currently Windows but considering
> FreeBSD
> 2. Site consists of result pages for auctions and items for sale (100
> per page)
> 3. MySQL (Dell Poweredge w/AMD) database server connected to my web
> server
> 4. Traffic, 30 million page loads/month
>
> I am trying to have the fastest page loads, averaging 100 items per
> result page.  I have read about using Apache's mod_python so I could
> use PSP.  Any help or tips are appreciated.
> 
> -Adam




More information about the Python-list mailing list