Home arrow Python arrow Page 2 - Karrigell for Python

Scripts and Services - Python

Since Python is not specifically designed for web development, a number of technologies created by Python users exist that aim to provide a web development environment. While the exact approach to the situation varies among each framework, a few of these frameworks really stand out in the crowd. One such framework is Karrigell. Read on to learn more.

  1. Karrigell for Python
  2. Scripts and Services
  3. Being HIP
  4. A Few More Features
By: Peyton McCullough
Rating: starstarstarstarstar / 15
January 03, 2006

print this article



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>"
print "Hello!"
print "<br /><br />"
print "Karrigell is configured and working."
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" ):
   print "Your name is", _name + "."
   print "What is your name?<br />"
   print "<form>"
   print "<input type='text' name='name' /><br />"
   print "<input type='submit' value='Proceed' />"
   print "</form>"

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:


Let's actually create the test.ks service:

def index():
   print "Index function."
def test():
   print "Test function."

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():
   print "What is your name?<br />"
   print "<form action='nameSubmit'>"
   print "<input type='text' name='name' /><br />"
   print "<input type='submit' value='Proceed' />"
   print "</form>"
def nameSubmit ( name ):
   print "Your name is", name + "."

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.

>>> More Python Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: