Yet Another Python Web Programming Question

D

Daniel Bickett

This post started as an incredibly long winded essay, but halfway
through I decided that was a terribly bad idea, so I've trimmed it
down dramatically, and put it in the third person (for humor's sake).

Once upon a time a boy named Hypothetical programmed in PHP and made
many a web application.

It would be a long while before he would find Python, and since that
time he would have no desire to ever touch PHP again.

He would, however, be compelled to write a web application again, but
in Python now, of course.

He would read the documentation of Nevow, Zope, and Quixote, and would
find none of them to his liking because:

* They had a learning curve, and he was not at all interested, being
eager to fulfill his new idea for the web app. It was his opinion that
web programming should feel no different from desktop programming.

* They required installation (as opposed to, simply, the placement of
modules), whereas the only pythonic freedom he had on his hosting was
a folder in his /home/ dir that was in the python system path.

* See the first point, over and over again.

All he really wanted was something that managed input (i.e. get, post)
and output (i.e. headers: "Content-type:"), and he would be satisfied,
because he wasn't an extravagant programmer even when he used PHP.

Python using CGI, for example, was enough for him until he started
getting 500 errors that he wasn't sure how to fix.

He is also interested in some opinions on the best/most carefree way
of interfacing with MySQL databases.

Thanks for your time,
 
D

Devan L

Take some time to learn one of the web frameworks. If your host doesn't
already have it, ask your host if they would consider adding it.
 
J

Jonathan Ellis

Daniel said:
He would read the documentation of Nevow, Zope, and Quixote, and would
find none of them to his liking because:

* They had a learning curve, and he was not at all interested, being
eager to fulfill his new idea for the web app. It was his opinion that
web programming should feel no different from desktop programming.

If you're coming from a PHP background, you'll find Spyce's learning
curve even shallower.

http://spyce.sourceforge.net

-Jonathan
 
A

and-google

Daniel said:
Python using CGI, for example, was enough for him until he started
getting 500 errors that he wasn't sure how to fix.

Every time you mention web applications on this list, there will
necessarily be a flood of My Favourite Framework Is X posts.

But you* sound like you don't want a framework to take over the
architecture of your app and tell you what to do. And, indeed, you
don't need to do that. There are plenty of standalone modules you can
use - even ones that are masquerading as part of a framework.

I personally use my own input-stage and templating modules, along with
many others, over standard CGI, and only bother moving to a faster
server interface which can support DB connection pooling (such as
mod_python) if it's actually necessary - which is, surprisingly, not
that often. Hopefully if WSGI catches on we will have a better
interface available as standard in the future.

Not quite sure what 500 Errors you're getting, but usually 500s are
caused by unhandled exceptions, which Apache doesn't display the
traceback from (for security reasons). Bang the cgitb module in there
and you should be able to diagnose problems more easily.
He is also interested in some opinions on the best/most carefree way
of interfacing with MySQL databases.

MySQLdb works fine for me:

http://sourceforge.net/projects/mysql-python/

(* - er, I mean, Hypothetical. But Hypothetical is a girl's name!)
 
D

Daniel Bickett

I neglected to mention an important fact, and that is the fact that I
am limited to Apache, which elminates several suggestions (that are
appreciated none-the-less).
 
J

Jorey Bump

I neglected to mention an important fact, and that is the fact that I
am limited to Apache, which elminates several suggestions (that are
appreciated none-the-less).

"Limited to Apache" is not the same as "using apache in a restricted
environment", so we may need more clarification.

If you are looking for a solution that sits on top of apache somehow, and
you have system administrative access, there are a lot of choices,
including ones that use mod_python. If something is not intended to
interface directly with apache, it can still be proxied through apache
while it runs on an alternate local port (a standalone app with an
embedded web server, for example).

If you mean that you're in a typical hosted environment with insufficient
privileges to install or configure much of anything, you might be stuck
with CGI. Since you mention in your original post that you have a folder
in your home directory that's in sys.path, your provider is trying to do
something to support python applications (hopefully, the path is specific
to your virtual host, to avoid namespace collisions). In any case, if
this was done to support mod_python, you can meet some of your criteria
with mod_python.publisher, but you will almost certainly want to use a
staging platform to develop your apps beforehand, since it is necessary
to either restart apache or touch imported modules after editing.

BTW, this is how I use Python for web applications myself: Each virtual
host gets a special directory prepended to the PYTHONPATH, in which the
bulk of my applications are created as packages. Then I use
mod_python.publisher to publish single modules that serve as interfaces,
converting values from requests and passing them on to the packages,
which I try to make web agnostic (in fact, I develop most of the backend
code locally before even trying it out on the web, so I can use it in
other application domains).

I've looked at other offerings, but as soon as I see proprietary markup
or commands embedded in HTML, I lose interest, so I feel your pain.
 
S

Sybren Stuvel

Daniel Bickett enlightened us with:
It would be a long while before he would find Python, and since that
time he would have no desire to ever touch PHP again.

My thoughts exactly.
He would, however, be compelled to write a web application again,
but in Python now, of course.

Same here :)
* They required installation (as opposed to, simply, the placement
of modules), whereas the only pythonic freedom he had on his hosting
was a folder in his /home/ dir that was in the python system path.

I can't help you here. For instance, if you want to get a proper
performance, you should install something like mod_python to get
Python functionality in Apache.
Python using CGI, for example, was enough for him until he started
getting 500 errors that he wasn't sure how to fix.

Check the web server's error logs.


My solution was to take a look at Cheetah. It's a template engine
that's written in Python. I've written a mod_python handler for it so
I can easily create & edit my website using Cheetah as a template
engine. Check out http://www.unrealtower.org/mycheetah if you want to
read more about the handler & other stuff I wrote. Perhaps you can
even help me improve it!

Sybren
 
T

Thomas Bartkus

> It was his opinion that
> web programming should feel no different from desktop programming.
<snip>

Should that ever become even remotely possible -

I'll be interested in web programming myself.
Thomas Bartkus
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top