Graham Dumpleton
graham.dumpleton at gmail.com
Mon Aug 18 21:26:06 EDT 2008
2008/8/18 Guillaume Poletto <polettog at gmail.com>: > Thanks for your answer > > 2008/8/18 Graham Dumpleton <graham.dumpleton at gmail.com> >> >> 2008/8/18 Poletto Guillaume <polettog at gmail.com>: >> > >> > Yes, I'm new to both Python programming language and mod_python >> >> If you are new to Python and want to write web applications, any >> reason why you didn't start out with one of the arguably more friendly >> higher level frameworks such as Django? > > I don't know.. no doubt that Django is great, but i was seduced by > writing my own handler and controlling requests by parsing URIs by > hand. > Note that if i'm new to Python, i'm experimented in web developement, > and also in writing CGIs (although this is not CGI here, i know). I > already know some low level things concerning HTTP headers (i wrote > some tools in C to parse urlencoded query strings, POST data and > netscape cookies). So except the import_module() part, i did > assimilate most of the manual. > If there was no "util" module to fetch form parameters, i would have > taken a look to a higher level framework, but the base mod_python > seems to provide all i need :) > Also, i was interesting in writing Apache modules in C, so i thought > using mod_python at low level was good to learn about how work > handlers and apache internals If you want to work at that level then you might also have a look at WSGI. http://www.python.org/dev/peps/pep-0333/ http://www.wsgi.org This is sort of a higher level form of CGI for Python. Whereas CGI is based one off execution, WSGI understands the concept of persistent processes. WSGI is also portable across hosting mechanisms and thus technically can work on top of CGI, mod_python, mod_wsgi, fastcgi, scgi, ajp plus standalone Python WSGI capable web servers. Thus, if you have some familiarity with CGI, WSGI will not be too foreign too you. As to higher level frameworks, if you want a more low level componentised framework which can work with WSGI, have a look at: http://werkzeug.pocoo.org/ >> If you are new to Python and have dropped down to the level of >> mod_python module importer already, I would suggest you run away. >> Instead have a look at one of the high level web frameworks for Python >> as you will be able to get onto developing your application much >> quicker and will not have to be worried about such low level details. >> :-) > > Thanks for the advice but i think i'll look to a higher level > framework in a future project. > I've all the time ! > Now i better understand what happens with "import" statements, i think > i will use them instead of import_module() and gracefully restart > apache at each update. > Now there's another problem : what's the right way to add another > import path ? Because i wanted to have the main source code outside > the directory in which is the handler module. > During my test, i did the tweak of adding dynamically my path to > sys.path list, but i find this a bit dirty. > So i found there was this apache directive "PythonPath" but according > to the manual, this is not recommanded to use it. > So what should i do? There is no problem using PythonPath. The only thing you shouldn't do is overlap the directories between it and the mod_python internal module importer. So, for normal Python modules/packages installed outside of document tree, the PythonPath is correct way of configuring their location. Graham
|