Welcome to your Pylons Web Application

Weren't expecting to see this page?

The gnuviechadminweb/public/ directory is searched for static files before your controllers are run. Remove this file (gnuviechadminweb/public/index.html) and edit the routes in gnuviechadminweb/config/routing.py to point the root path to a 'hello' controller we'll create below:

 map.connect('', controller='hello', action='index')

Getting Started

You're now ready to start creating your own web application. To create a 'hello' controller, run the following command in your project's root directory:

gnuviechadminweb$ paster controller hello
This generates the following the following code in gnuviechadminweb/controllers/hello.py:
import logging

from gnuviechadminweb.lib.base import *

log = logging.getLogger(__name__)

class HelloController(BaseController):

    def index(self):
        # Return a rendered template
        #   return render('/some/template.mako)
        # or, Return a response
        return 'Hello World'

This controller simply prints out 'Hello World' to the browser. Pylons' default routes automatically set up this controller to respond at the /hello URL. With the additional route described above, this controller will also respond at the root path.

Using a template

To call a template and do something a little more complex, this following example shows how to print out some request information from a Mako template.

Create a serverinfo.mako file in your project's gnuviechadminweb/templates/ directory with the following contents:

<h2>
Server info for ${request.host}
</h2>

<p>
The URL you called: ${h.url_for()}
</p>

<p>
The name you set: ${c.name}
</p>

<p>The WSGI environ:<br />
<pre>${c.pretty_environ}</pre>
</p>
Then add the following to your 'hello' controller class:
    def serverinfo(self):
        import cgi
        import pprint
        c.pretty_environ = cgi.escape(pprint.pformat(request.environ))
        c.name = 'The Black Knight'
        return render('/serverinfo.mako')
You can now view the page at: /hello/serverinfo