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.
Although I'm not a huge fan of the practice, tags can be generated within Python scripts, as shown here in tagTest.py:
from HTMLTags import *
print CENTER ( B ( "Test." ) )
Sessions are also possible with Karrigell, and Karrigell presents a nice, object-oriented approach to sessions. Let's create a simple script that demonstrates sessions in Karrigell. Upon accessing the script for the first time, the user will receive a “lucky number” of sorts. If the user refreshes, the same number will still appear since it will be stored inside of a session. However, the user will be given the option of resetting his or her lucky number by closing the session. Create a Karrigell service named luckyNumber.ks in which to house this script:
user = Session()
def index(): if not "luckyNumber" in dir ( user ): user.luckyNumber = random.randint ( 0, 20 ) print "Your lucky number:", user.luckyNumber print "<br /><br />" print "<a href='reset'>Reset Lucky Number</a>" def reset(): user.close() print "Your lucky number has been reset." print "<br /><br />" print "<a href='index'>Back</a>"
Karrigell offers four methods of web development using Python: Python scripts, Karrigell services, HTML Inside Python and Python Inside HTML. Each method is unique and has its benefits, but they all share one thing in common: each method is very simple to employ in applications. Karrigell approaches web development in a straightforward manner, presenting simple solutions to a simple problem. Even installing Karrigell and configuring Apache and Karrigell to interact is a surprisingly simple process. Because of all this, Karrigell appeals to both newcomers and experts in Python alike.