Keerati Inochanon
unselfishly at gmail.com
Mon Jan 17 09:21:05 EST 2005
That explains a whole lot why some of the things I did worked (and some did not). I have an idea now how to make my code works properly. Thank you very much! On Mon, 17 Jan 2005 19:30:45 +1100, Graham Dumpleton <grahamd at dscpl.com.au> wrote: > > On 17/01/2005, at 5:50 PM, Graham Dumpleton wrote: > > > Keerati Inochanon wrote .. > >> Hi, > >> > >> I am a couple-of-day old python programmer. I decided to give a shot > >> at mod_python. I successfully installed mod_python, but I am still > >> trying to work with vampire. I would like psp files to be able to call > >> functions in other modules (ie. a .py file). Before installing > >> vampire, I was able to do this by calling filename/function (eg. <form > >> action="authentication/login" method="post" name="doe"> ) . If I do > >> the same thing now, it will give me a 404 file not found error. > >> Putting http://domain/filename/function in the location bar will not > >> work either. > >> > >> ... > >> > >> I am using the .vampire and default-handlers.py as provided with the > >> source as the default content handler. Vampire is now mapping html > >> extension to psp. The psp file snippet is below: > >> > >> <html> > >> <form action="authentication/login" method="post" name="auth"> > >> Username: <input type="text" name="username"></input><br> > >> Password: <input type="password" name="password"></input><br> > >> <input type="hidden" name="isFirst" value="False"></input> > >> <input type="submit" value="Login"> > >> </form> > >> </html> > >> > >> Any help will be much appreciated. Thank you very much! > > > > The form is merely a POST against a URL, specifically > > "authentication/login". > > Using Vampire, you should therefore have a file: > > > > authentication/login.py > > > > In this file it would have a handler defined as: > > > > def handler(req,username,password,isFirst): > > ... > > > > The method is just "handler()" in this case, as the URL being posted > > against > > has no extension on it. > > > > At least that is how it should work. I'll test it when I get home and > > post again > > then. > > Have twigged now on what you are doing differently. > > When using PSP directly, your login handler was being implemented in > the style expected by mod_python.publisher. That is, for > "authentication/login" > you would have had a file called "authentication.py" with a function in > it called "login". > > In Vampire, it does not use the mod_python.publisher style of mapping > URLs to > actual files. In mod_python.publisher generally all but the last part > of the > URL identifies the path to the file and the last part identifies the > method > within the file. > > In Vampire, the whole URL (or as much as possible) is used to identify > the > path to the file. Any extra is supplied in the "req" object as > "path_info". > The method executed in the file will be handler(), or if the last > component > on the URL used to identify the file has an extension, the > handler_extn(), > method where "extn" is replaced with the actual extension. > > What this means is that when using mod_python.publisher, there can be > multiple methods in the same code file which are associated with > different > resource URLs. If an extension is used and AddHandler is set > appropriately, > the extension has no real meaning. > > In Vampire, each code file only has methods related to one specific > resource. > There may however be different methods for delivering up the resource in > different formats. Which is called is dictated by the extension used in > the > URL. > > Thus in Vampire, mapping to functions is different. The other thing to > know > is that the handler functions in Vampire follow the standard mod_python > form. That is, its return value is a status value. In > mod_python.publisher > the return value will be the actual content, which if not HTML, will be > converted to HTML. If a specific status has to be returned an exception > is > instead raised. > > Note though that Vampire supports the mod_python.publisher like > extension > of being able to accept form parameters as method parameters of the > handler method. In doing this though, it is mandatory that the first > argument of the handler method still be the "req" object whereas in > mod_python.publisher accepting the req object is optional and could be > placed in any position. > > That said, if the only method in authentication.py to be called via a > URL is login(), you could instead renamed authentication.py to login.py > and change the method from login() to handler() and the the action in > form would just be "login". You obviously still need change the > handler() > method to be implemented more in the form of a standard handler and not > a mod_python.publisher method. > > Hope this helps. > > -- > Graham Dumpleton (grahamd at dscpl.com.au) > >
|