[Tutor] hand-holding for web development

nitin chandra nitinchandra1 at gmail.com
Tue Oct 18 22:23:24 CEST 2005


Thanks Jay

On 10/18/05, Jay Loden <python at jayloden.com> wrote:
> You need an Apache config section to tell it what to use mod_python on and
> how. For example, in httpd.conf or a separate file in your conf.d directory

i guess the <directort</directory> can be added only in one of the conf file.
Which one should i add in?


> for apache:
>
> <Directory /var/www/html/>
>       AddHandler      mod_python .py
>       PythonHandler test
>       PythonDebug On
> </Directory>
>
> tells Apache to use mod_python on all .py files in my /var/www/html directory
> (which is also the document root on my server).
>
> Once that's loaded you should be able to run whatever your python code through
> a handler. For example, saving this as test.py:
>
> #
> #mod_python super basic test script
> #
> from mod_python import apache
>
> def handler(req):
>   req.content_type = "text/html"
>   req_file = basename(req.uri)
>   if req.header_only:
>      return apache.OK
>
>   else:
>      req.write("mod_python is working")
>      return apache.OK
>
> # end of script
>
> This should print "mod_python is working" to the browser if you visit
> http://yoursite.com/test.py
>
> Remember that you need to restart/reload apache after any config change. The
> basic gist is that any .py file you load in the /var/www/html runs the script
> "test.py" (PythonHandler test) and executes the "handler()" function within
> the script. NOTE: this can be very non-intuitive, becuase running
> http://yoursite.com/test.py has exactly the same result as
> http;//yoursite.com/foo.py - because they're both simply running the handler
> script, test.py, for ALL .py files in the directory. That means that your
> PythonHandler script needs to dispatch other scripts or load special pages in
> order to get different code to run. Also note that there are some pre-written
> Handler scripts that come with mod_python that can often do most of your work
> for you.
>
> You'll probably want a good tutorial on using mod_python to make sense of all
> this, because it's not really intuitive and it works differently than
> traditional cgi programming. Take a look at:
> http://modpython.org/live/current/doc-html/
> to get you started, it's a lot more detailed and will probably answer your
> questions better.

Thaks you. could you please guide how to interface Django with
mod_python, for effectively using in web site development?

>
> -Jay

Thanks You

Nitin


More information about the Tutor mailing list