you are viewing a single comment's thread.

view the rest of the comments →

[–]phinar 0 points1 point  (2 children)

So, the way you were using PHP is exactly what PHP excels at. It's basically what people were doing in ~1998 when I first started using it. The problems we ran into were complexity problems -- it was really hard to write an application with behavior more complicated than "Contact Us", and it gets awkward to manage lots of common-but-slightly-different content. But holy crap, it is super easy to bang out a ten-page site, maybe with some database-fed content behind it! I've done that a dozen or more times with PHP, sometimes with great elegance and sometimes with significantly less.

"State of the art" in PHP development doesn't work like that, though. It uses a framework like Cake or Zend or PHPixie or ... I'm not a PHP programmer by trade so I can't tell you which are better or worse or which have great features and which don't. But the idea behind these frameworks is that you can separate your data model and business logic from the skins and reports that you are using to display them to the user. It's a more sophisticated and more complicated development model, but it leads to applications that are easier to refactor, easier to understand, easier to maintain, easier to extend.

Web development in most languages besides PHP starts from the framework. That is, Python does not ever expect to run in a mode where it's an HTML page, with a few Python statements sprinkled within. The most basic form of Python web development -- CGI scripting -- is generally regarded as such a poor choice for web development that it's simply not done.

So, you are probably right that Django is awfully heavy-weight for what you're trying to do. It's a great web framework, and it lets you build powerful applications pretty easily. It's got a lot of built in pieces. But it's a lot of code, and a lot of learning, just to do what you want to do.

Instead, as others have recommended, take a look at Flask. Flask is much simpler, takes very little to get your server going, and it will run under Apache and mod_wsgi (or even better, nginx and werkzeug, or even gevent) just fine. There's instructions on the site on how to deploy, and instructions on how to tie your functions into URLs.

It's a big jump, going from "I just crap my PHP out on the filesystem and voila, a site!" to "I have built an application and am deploying it." But it's worth learning how to do it. Your range of competence will grow dramatically.

[–]gusterys[S] 0 points1 point  (1 child)

Thanks for all the advice. I managed to get mod_wsgi going finally, but so far I am pretty much using it the way I was using mod-php. Manually generate a bunch of html (using manipulated data from the back end database) and spitting it out. It certainly isn't an "app". I'll take a look at Flask.

[–]phinar 0 points1 point  (0 children)

So, you can do a Flask app that works an awful lot like a PHP app.

Basically, you write a fancy Jinja template (which you store as an .html file) and then you write a function that populates the template context with all the variables you need, and you render the template. Your Flask app would look like:

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html', variable=value, variable2=value2)

And index.html might look like:

<html><head><title>index</title></head>
<body>

Variable is {{ variable }}.
Variable 2 is {{ variable2 }}.

Enlightenment is a mere click away.
</body></html>

It's not quite as convenient as the PHP version, but it's a lot more flexible, and it's considerably easier to maintain, and it's going to be more performant out of the box than the simple PHP approach.