Skip to content

Instantly share code, notes, and snippets.

@jdstanhope
Created March 3, 2013 19:08
Show Gist options
  • Save jdstanhope/5077709 to your computer and use it in GitHub Desktop.
Save jdstanhope/5077709 to your computer and use it in GitHub Desktop.
App Engine Template using Jinja2 template engine
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import webapp2
import jinja2
root_dir = os.path.dirname(__file__)
search_paths = [os.path.join(root_dir, 'templates')]
env = jinja2.Environment(loader=jinja2.FileSystemLoader(search_paths))
class MainHandler(webapp2.RequestHandler):
def get(self):
template = env.get_template('main.html')
content = template.render({})
self.response.write(content)
routes = [webapp2.Route(r'/', MainHandler, name='main')]
app = webapp2.WSGIApplication(routes, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment