The first two methods Karrigell presents to developers are scripts and services. A script is simply a Python script that uses print to output to the user's browser. If you haven't done so already, create a testarea directory, and we can begin our first script. Create the file test.py: print "<center>" Point your browser to the file, and if you have Karrigell set up as described above, you should see the message described above. Form data is fairly easy to handle with Python scripts. Let's create a simple script whose output differs depending on whether the user has specified his or her name in a form. Name it askName.py: if QUERY.has_key ( "name" ): Services are written like Python scripts, too. However, they are designed to map requests to functions defined by the user. The desired function is passed along in the URL after the name of the service. For example, the following URL would call the test function of the service test.ks: http://localhost/testarea/test.ks/test Let's actually create the test.ks service: def index(): If you call the script without passing a function name, then you will be redirected to the index function. If you call the script passing the test function name, then the test function will be executed. Attempting to call a function not defined will produce an error. Configuring services to accept form data is quite easy. Let's recreate askName.py as the service askName.ks: def index(): Of course, making every single one of your service's functions accessible to the outside world could be a security hazard. To prevent users from accessing certain functions, simply prefix them with an underscore: def _private(): Attempting to access the _private function will result in an error message.
blog comments powered by Disqus |