Web.py: Difference between revisions
(Created page with "= Web.py demo code = One of the [http://webpy.org/ Web.py] demos is set up on hcil2. <br /> http://hcil2.cs.umd.edu/aq/webpy/todo_demo/ <br /> /fs/hcil2/aq/webpy/todo_demo/ /...") |
|||
Line 13: | Line 13: | ||
On our servers, you have 3 options for running Web.py code: | On our servers, you have 3 options for running Web.py code: | ||
1. Plain CGI | 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. | 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. | ||
Line 20: | Line 20: | ||
3. WSGI installed with Apache | 3. WSGI installed with Apache | ||
Regular WSGI on port 80 requires some configuration by staff. You'll want this for production applications. | Regular WSGI on port 80 requires some configuration by staff. You'll want this for production applications. | ||
= Debugging = | = Debugging = |
Latest revision as of 20:21, 7 June 2013
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.