Δευτέρα 14 Απριλίου 2008

Cherry Pies

Recently i decided to learn about web python frameworks.A friend of mine suggested that i should use CherryPy.

what is CherryPy though?Taken from its web site:
"CherryPy is a pythonic, object-oriented HTTP framework."

CherryPy can be downloaded from the following link.
http://www.cherrypy.org/wiki/CherryPyDownload

If you have allready messed around with these kind of web frameworks you would know that by default they usually run their own web server.But what happens when you want to associate Cherrypy with apache. There are many methods to associate CherryPy with apache . The one that i wanted to use was the combination of cherrypy + mod_python.Trying the configuration from the tutorial , it gave me a working server with the use of apache mod_python , but i lost my web directory which i didn't want it to happen , so i decided after a bit of searching and failures to mess arround with the virtualhosts of apache and this is the result.


Listen 8888
NameVirtualHost *:8888

< VirtualHost>
DocumentRoot "/"
ServerName localhost
< Location>
Options FollowSymlinks
AllowOverride None
Order deny,allow
Allow from all
SetHandler python-program
PythonHandler cherrypy._cpmodpy::handler
PythonOption cherrypy.setup myapp::setup_server
PythonDebug On
PythonPath "['/home/cherry/'] + sys.path"
< /Location>
ErrorLog "/var/log/httpd/error_cherry.log"
CustomLog "/var/log/httpd/access_cherry.log" common
< /VirtualHost>


After that i was able to link to my cherrypy site through this link.
http://localhost:8888/

While messing with cherrypy , you will see this interesting error in your web browser "Unrecoverable error in the server" , but nothing about the error that caused it.After a little search through the internet i found this interesting patch which brings the error closer to you.


--- _cpmodpy.py
+++ _cpmodpy.py
@@ -202,7 +202,7 @@
except:
tb = format_exc()
cherrypy.log(tb)
- s, h, b = bare_error()
+ s, h, b = bare_error(tb)
send_response(req, s, h, b)
return apache.OK


Also another problem that occured to me was with the PythonPath,tutorial of cherrypy suggested that the PythonPath should be like this

PythonPath "sys.path+['/home/cherry/']"

after a little bit of search,django helped a little , i found out that you should put your python folder first and after that the sys.path.

PythonPath "['/home/cherry/'] + sys.path".

And just because i mentioned django here is a link about it

http://www.djangoproject.com/download/