Web.py

From hcil
Revision as of 20:21, 7 June 2013 by Mgubbels (talk | contribs) (→‎Options for running on HCIL machines)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Web.py demo code

One of the Web.py demos is set up on hcil2.
http://hcil2.cs.umd.edu/aq/webpy/todo_demo/
/fs/hcil2/aq/webpy/todo_demo/ /fs/hcil2/aq/webpy/todo_demo/

This is a slight adaptation of this example from the Web.py tutorial.

If you move the code to a different directory, you'll need to change a path in the .htaccess and templates/index.html files.

Options for running on HCIL machines

On our servers, you have 3 options for running Web.py code:

1. Plain CGI The above example is running this way, as plain CGI. This is easiest for getting started but slower to execute (≈200 ms vs. ≈20 ms per query). This is probably fine if you're just testing on your own. To get nice, clean URLs, you'll need an .htaccess file. See the one in the demo for an example.

2. WSGI built-in test server This is much faster and still very simple. However, it is only good for testing since it runs on high ports and you must be logged in to use it. Just run your code (./todo.py) and point your browser to http://hcil2.cs.umd.edu:8080/.

3. WSGI installed with Apache Regular WSGI on port 80 requires some configuration by staff. You'll want this for production applications.

Debugging

When debugging a Web.py application, you can put this line near the top of your file:

  web.config.debug = True 

Be sure to turn it off when you're done, since it might expose internal server details that could be useful to an attacker.

To see the hcil2 log files, type:

  tail /var/apache/logs/error_log 
  tail /var/apache/logs/access_log 

About Web.py

The main advantages of Web.py are that it's quick to learn and easy to set up, even on the HCIL servers where we don't have root. The Web.py tutorial is short and covers quite a bit.

Web.py is a minor player with regard to web frameworks—no competition to GAE, Web2py, Django, and such. If GAE works for what you're doing, it's may be your best bet. However, Web.py does have a nice core set of features: templating, sessions, DB integration, basic OpenID, etc. In particular, the templating language simplifies code dramatically. Also, the database module makes it easy to start with the built-in SQLite when you're resing and then migrate to MySQL when you need to. Web.py has been actively developed and maintained since 2007.