-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
40 lines (33 loc) · 1.02 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import wsgiref.handlers
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
def throwNotFound(self):
self.error(404)
template_values = {
'foo': 'bar',
}
path = os.path.join(os.path.dirname(__file__), 'templates/404.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render(path, template_values))
class notfoundHandler(webapp.RequestHandler):
def get(self):
throwNotFound(self)
class MainHandler(webapp.RequestHandler):
def get(self):
template_values = {
'foo': "bar",
'bar': "foo"
}
path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render(path, template_values))
application = webapp.WSGIApplication([
('/', MainHandler),
('/.*', notfoundHandler)
], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()