On Wed, Oct 8, 2008 at 9:57 AM, Sivaram Kannan <[EMAIL PROTECTED]> wrote:
> Hi all,
> When I give the following url "http://localhost/first.py"; the function
> handler is getting executed. But when I give the url
> "http://localhost/first.py/get_time"; the function get_time is not
> getting called. What should I do to call anyfunction in a python
> script through mod_python?

Instead of using your own handler, i think you should use
mod_python.publisher as your handler. In addition, whatever you want
to print, you should return it from your method and the publisher
handler would do the rest to display in the browser. I've not used
publisher class, but I think it works this way.

If you rewrite your http configuration snippet and code as follows,
you should be able to access get_time() function using
http://localhost/first.py/get_time url:

HTTP CONFIGURATION SNIPPET
    <Directory "/var/www/python/">
       Options Indexes FollowSymLinks MultiViews
       AllowOverride None
       Order allow,deny
       allow from all
       SetHandler mod_python
       PythonHandler mod_python.publisher
       PythonDebug on
    </Directory>


REWRITTEN first.py SCRIPT
import time

def get_time():

       html = """
               <html><head>
               <title>get_time function</title>
               </head>
               <body>
                       <h1>get_time function</h1>
                       <hr>
                               The local time of this server is:  %s
<br>
                               The timezone of this server is  :  %s
<br>
               </body>
       </html>""" % (time.ctime(time.time()), time.timezone/3600)
       return html

TIP: It is always a good practice to use a separate directory instead
of the apache root directory to execute server side script. In your
case, you can create an alias as follows and access the method using
http://localhost/python/first.py/get_time url:
    Alias /python/ "/var/www/python/"

-- 
Regards,
Bhuvaneswaran A
www.livecipher.com
GPG: 0x7A13E5B0
_______________________________________________
To unsubscribe, email [EMAIL PROTECTED] with 
"unsubscribe <password> <address>"
in the subject or body of the message.  
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to