]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/public/index.html
Small indentation fix to model/__init__
[bluechips.git] / bluechips / public / index.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2    "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5   <title>Pylons Default Page</title>
6   <style>
7     body { background-color: #fff; color: #333; }
8
9     body, p {
10       font-family: verdana, arial, helvetica, sans-serif;
11       font-size:   12px;
12       line-height: 18px;
13     }
14     pre {
15       background-color: #eee;
16       padding: 10px;
17       font-size: 11px;
18       line-height: 13px;
19     }
20
21     a { color: #000; }
22     a:visited { color: #666; }
23     a:hover { color: #fff; background-color:#000; }
24   </style>
25 </head>
26 <body>
27
28 <h1>Welcome to your Pylons Web Application</h1>
29
30 <h2>Weren't expecting to see this page?</h2>
31
32 <p>The <tt>bluechips/public/</tt> directory is searched for static files
33  <i>before</i> your controllers are run. Remove this file (<tt>bluechips/public/index.html</tt>)
34   and edit the routes in <tt>bluechips/config/routing.py</tt> to point the
35   <a href="/">root path</a> to a 'hello' controller we'll create below:
36   <pre> map.connect('', controller='hello', action='index')</pre>
37 </p>
38
39 <h2>Getting Started</h2>
40 <p>You're now ready to start creating your own web application. To create a 'hello' controller,
41   run the following command in your project's root directory: 
42 <pre>
43 BlueChips$ paster controller hello
44 </pre>
45
46   This generates the following the following code in <tt>bluechips/controllers/hello.py</tt>:
47 <pre>
48 import logging
49
50 from bluechips.lib.base import *
51
52 log = logging.getLogger(__name__)
53
54 class HelloController(BaseController):
55
56     def index(self):
57         # Return a rendered template
58         #   return render('/some/template.mako)
59         # or, Return a response
60         return 'Hello World'
61 </pre>
62 </p>
63 <p>This controller simply prints out 'Hello World' to the browser. Pylons' default routes
64   automatically set up this controller to respond at the <a href="/hello">/hello</a> URL.
65   With the additional route described above, this controller will also respond at the
66   <a href="/">root path</a>.
67 </p>
68
69 <h3>Using a template</h3>
70 <p>To call a template and do something a little more complex, this following example
71    shows how to print out some request information from a
72   <a href="http://www.makotemplates.org">Mako</a> template.
73 </p>
74 <p>Create a <tt>serverinfo.mako</tt> file in your project's <tt>bluechips/templates/</tt>
75   directory with the following contents:
76 </p>  
77 <pre>
78 &lt;h2&gt;
79 Server info for ${request.host}
80 &lt;/h2&gt;
81
82 &lt;p&gt;
83 The URL you called: ${h.url_for()}
84 &lt;/p&gt;
85
86 &lt;p&gt;
87 The name you set: ${c.name}
88 &lt;/p&gt;
89
90 &lt;p&gt;The WSGI environ:&lt;br /&gt;
91 &lt;pre&gt;${c.pretty_environ}&lt;/pre&gt;
92 &lt;/p&gt;
93 </pre>
94
95 Then add the following to your 'hello' controller class:
96 <pre>
97     def serverinfo(self):
98         import cgi
99         import pprint
100         c.pretty_environ = cgi.escape(pprint.pformat(request.environ))
101         c.name = 'The Black Knight'
102         return render('/serverinfo.mako')
103 </pre>
104
105 You can now view the page at: <tt><a href="/hello/serverinfo">/hello/serverinfo</a></tt>
106 </p>
107 </body>
108 </html>