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.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |