DevelopingAWikiInWeb.pyPart1
From Wiki
I've toyed with various web frameworks over the years, and for whatever reason, web.py is the first one which "stuck". Here, I'll go through the process of writing a basic wiki in web.py.
let's start by getting "hello world" to work. but first let's get web.py installed. if your distro ships with a recent web.py, you have it easy. otherwise, here's how to install from source.
cd /tmp wget -O - http://webpy.org/static/web.py-0.33.tar.gz | gunzip | tar x cd web.py-0.33 su python setup.py install --prefix=/opt/web.py-0.33 exit
at this point I'd use my Splice utility to symlink all of the files from /opt/web.py-0.33 into /usr/local.
splice /opt/web.py-0.33/ /usr/local/
most likely, your python install will search for libs in /usr/local, so at this point you should be good. let's check:
cell@kosh$ python Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import web >>>
if that didn't work (or if you'd rather not splice into /usr/local), you can add a path component to your $PYTHONPATH environmental variable. for example, here's how you'd add /opt/web.py-0.33:
cell@kosh$ export PYTHONPATH=/opt/web.py-0.33/lib/python2.5/site-packages cell@kosh$ python Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print sys.path ['', '/opt/web.py-0.33/lib/python2.5/site-packages', '/usr/lib/python2.5', ...
now, let's grab 'hello world' from the web.py tutorial (http://webpy.org/tutorial3.en):
#!/usr/bin/env python
import web
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
app.run()
and run it:
cell@kosh$ python code.py http://0.0.0.0:8080/
now open up a web browser and point it at 'http://localhost:8080'. you should see "Hello, world!" in your web browser, and you should see this in your terminal:
cell@kosh$ python code.py http://0.0.0.0:8080/ 127.0.0.1:43323 - - [06/Apr/2010 13:21:42] "HTTP/1.1 GET /" - 200 OK
if you've gotten that far, continue on to part 2: DevelopingAWikiInWeb.pyPart2
