Contrast[1] with python:
mkdir cgi-bin
cat <<'eof' > cgi-bin/hello.py
#!/usr/bin/env python3
print("Content-type: text/plain")
print()
print("Hello, world")
eof
#try to run:
./cgi-bin/hello.py
bash: ./cgi-bin/hello.py: Permission denied
#fix error:
chmod u+x ./cgi-bin/hello.py
#test in console:
./cgi-bin/hello.py
Content-type: text/plain
Hello, world
#Ok, does it work on the web?
python3.4 -m http.server --cgi 8000 --bind 127.0.0.1
#open localhost:8000/cgi-bin/hello.py
So, how can I claim that this convoluted mess is "simpler" than php? Because everything is right there, and everything can be explained conciesly (contrast with apache configs, getting the www-user right etc). You could build on what the students know of print() and string interpolation/concatenation to output html/use templates etc.Is this how I would start teaching web programming in python? Probably not -- but it might be useful as one approach, assuming we've started with doing some stdin/stdout stuff, and showing how we can do the same on the web. Crucially showing how if you know how to read a csv file with values, do some aggreation and format it as a text table, you can output it as html, as text over the web, or even as json paired with javascript. That again generalises to database access ... etc etc. It's python (and "invisible" c) all the way down.
[1] Comparing using a fully wrapped up install of webserver+php (either mod-php or fcgi or what not) would a) not be fair, because if you really learn python, you have all the tools to examine the whole stack (well down to the OS level anyway), and b) fair comparision wouldn't be to python but rather with something like web2py, that also bundles a lot of infrastructure.
YMMV and all that, my only point was that there isn't really anything "simple" about web development -- it's distributed development with not very clearly defined security, state or even messaging semantics -- it's a mess. A useful mess, but a mess.
[edit: formatting, spelling. Aslo I agree flask is probably a much nice place to start, if one isn't building on an introduction involving text/console i/o]
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__": app.run() print "hello world"
beats PHP: <?php echo "hello world" ?>http://modpython.org/live/mod_python-3.3.1/doc-html/pyapi-ps...
But it's not a very good architecture, in the meanwhile we had better approaches, such as MVC and MVVM.
Anyway, CS is not web programming, but should focus on the fundamentals of computer science, for which there are far better languages than PHP.