Karrigell for Python - A Few More Features (
Page 4 of 4 )
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:
import random
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>"
Conclusion
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.