The SnakeLib that comes with mod_snake contains a PyMod to do embedded Python processing. This is a very easy and simple way to create dynamic content within your web-page. For more information on mod_snake_emb, check the mod_snake_emb section in the snake_lib documentation.
First, ensure that mod_snake is correctly installed - if not, go back to section 2.1. To use mod_snake_emb, you will first need to load that module. Assuming you untarred your mod_snake distribution into /home/httpd/mod_snake, you could enter the following directives into your httpd.conf file:
SnakeModuleDir /home/httpd/mod_snake/snake_lib
SnakeModule mod_snake_emb.SnakeEMBThe next step is to enable embedded Python for certain pages on your site. The mod_snake_emb module provides a number of directives to tweak its configuration. They are, SnakeEMB, SnakeEMBCache, SnakeEMBErrSend, and SnakeEMBLogFile. For reference information, see the snake_lib document.
Say you have a directory under htdocs called 'emb_python', and that this is the directory containing HTML documents that you would like to process prior to sending to the clients. To enable the processor, add to the .htaccess file in the emb_python directory:
SnakeEMB on
SnakeEMBErrSend on
SnakeEMBCache onThis will enable embedded Python processing for this entire directory. The next step is to setup a test file to show how the embedding works. Create a file called emb_python/emb.html, and add the following to it:
[-import time-]
The time is: [+time.ctime(time.time())+]After starting the webserver, and loading the emb.html page, you should see the following page:
The time is Thu Jun 22 9:00:00 2000
(or something similar)Now change this to contain an error. Change the first line from [-import time-] to [-fooimport time-]. Since we have the SnakeEMBErrSend directive 'on', the stack trace will be sent to our browser instead of sent out to a log file.