Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1395

Show
Ignore:
Timestamp:
10/09/06 16:36:33
Author:
lawouach
Message:

Updated docstring with a basic example on how to use the _cpmodpy module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpmodpy.py

    r1319 r1395  
    1 """Native adapter for serving CherryPy via mod_python""" 
     1"""Native adapter for serving CherryPy via mod_python 
     2 
     3Basic usage: 
     4 
     5########################################## 
     6# Application in a module called myapp.py 
     7########################################## 
     8 
     9import cherrypy 
     10 
     11class Root: 
     12    @cherrypy.expose 
     13    def index(self): 
     14        return 'Hi there, Ho there, Hey there' 
     15 
     16 
     17# We will use this method from the mod_python configuration 
     18# as the entyr point to our application 
     19def setup_server(): 
     20    cherrypy.tree.mount(Root()) 
     21    cherrypy.config.update({'environment': 'production', 
     22                            'log.screen': False, 
     23                            'show_tracebacks': False}) 
     24    # You must start the engine in a non-blocking fashion 
     25    # so that mod_python can proceed 
     26    cherrypy.engine.start(blocking=False) 
     27 
     28########################################## 
     29# mod_python settings for apache2 
     30# This should reside in your httpd.conf 
     31# or a file that will be loaded at 
     32# apache startup 
     33########################################## 
     34 
     35# Start 
     36DocumentRoot "/" 
     37Listen 8080 
     38LoadModule python_module /usr/lib/apache2/modules/mod_python.so 
     39 
     40<Location "/"> 
     41        PythonPath "sys.path+['/path/to/my/application']"  
     42        SetHandler python-program 
     43        PythonHandler cherrypy._cpmodpy::handler 
     44        PythonOption cherrypy.setup myapp::setup_server 
     45        PythonDebug On 
     46</Location>  
     47# End 
     48 
     49The actual path to your mod_python.so is dependant of your 
     50environment. In this case we suppose a global mod_python 
     51installation on a Linux distribution such as Ubuntu. 
     52 
     53We do set the PythonPath configuration setting so that 
     54your application can be found by from the user running 
     55the apache2 instance. Of course if your application 
     56resides in the global site-package this won't be needed. 
     57 
     58Then restart apache2 and access http://localhost:8080 
     59""" 
    260 
    361import cherrypy 

Hosted by WebFaction

Log in as guest/cpguest to create tickets