-
Notifications
You must be signed in to change notification settings - Fork 1
Web framework
Basium contains a web framework that can be used to build dynamic web pages using python
The web framework can be used in two ways
- Standalone
- Apache, as a mod_wsgi module
Included in basium is an example of how to configure apache (apache-site)
The URL specified by the user is mapped to the filesystem (directory, file). If the file is a python script (extension .py), the script is imported and the specified function is executed.
If the file is not a python script, the file is returned to the user.
Example
documentroot is /var/www
User requests http:///index.html The file at /var/www/index.html is returned, unmodified
User requests http://index.py The file at /var/www/index.py is imported and then the _default() function is called. The index.py should have a content similar to the following:
def _default():
print """
<html>
<head>
<title>ErgoTime</title>
</head>
<body>
"""
User requests http:///customer/list.py The file at /var/www/customer.py is imported, and the list() function is called
An imported .py file has a number of module variables defined.
variable | description |
---|---|
db | a reference to an open database, accessible through basium ORM |
log | send output to the log (syslog, apache log) |
request | data in the http request |
response | data that should be sent back to the client |
any data sent to stdout/stderr is returned to the client