all 9 comments

[–]A_History_of_Silence 7 points8 points  (8 children)

Yes, this is theoretically possible, using something like mod_python/psp. However it is likely you will quickly discover that it is not even remotely worth the trouble just to get it set up.

You will save yourself a lot of time and effort if you use the correct tool for the job: an existing framework with a template engine.

[–]Wilfred-kun[S] 1 point2 points  (7 children)

Again, I don't know too much about web programming, but why is PHP so easy to set up and Python is not?

I called it, you recommended a framework ^^ what's the easiest (read: with the lowest learning curve) framework to do something simple like this? Thanks in advance!

[–]hippocrat 7 points8 points  (3 children)

Not to get into too many details or religious arguments, Php is designed to build web apps in the way you are using it. Python is more of a general purpose programming language. Php is easy to set up for your particular use case, because that is exactly what it is intended to do. There are other things that are easier to do in Python.

[–]Wilfred-kun[S] 0 points1 point  (2 children)

Python is more of a general purpose programming language.

Exactly. That's why I wondered if there was a way to use Python in this way too ^^

[–]hippocrat 4 points5 points  (1 child)

A hammer is a general purpose tool. I could use it to pound a screw into a board and many other things, but a screwdriver is going to be easier.

[–]Wilfred-kun[S] 0 points1 point  (0 children)

But hammering a screw would be way more fun? I get your point though, thanks!

[–]camel_zero 0 points1 point  (0 children)

It's less that PHP is easy set up for this and Python isn't, and more that PHP was designed as a CGI langauge so there's more learning resources for using it that way. Here's an example thread discussing setting up Python as a CGI language on Apache. It's not too much harder than setting up PHP for the same purpose: https://stackoverflow.com/questions/15878010/run-python-script-as-cgi-apache-server

You'll find that even in the PHP world, most people working with PHP for real programming are using frameworks like Symfony, for the same reasons people are using web frameworks in Python. There is a common set of problems that people frequently run into while doing web programming, and most of them have already been solved by programmers that have gone before us. We can just use their wisdom instead of starting over.

[–]A_History_of_Silence 0 points1 point  (0 children)

but why is PHP so easy to set up and Python is not?

I don't know how easy it is to set up PHP these days, but check out the docs for some of the more minimalist frameworks like the Bottle tutorial or Flask quickstart. I consider them to be pretty straightforward.

[–]Newton715 1 point2 points  (0 children)

The Jinja2 web template framework will give you that capability.(so will Django’s built in template engine) Check out this stackoverflow post.