0

I am trying to go from python2.5 to python 2.7 in google app engine.

I just cannot get index.html up and going. I get a blank webpage, and nothing more. index.html is in the same directory as the .yaml and .py files.

I cannot find out how to make it work, cause there is no such tutorials or examples or anything that tells you how to render index.html.

What I found are examples that write out 'Hello World!'. I've found some 'almost there'-examples, but it's not quite there.

Here are app.yaml and main.py

application: myapp
version: main
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /(.*\.(gif|png|jif|jpg|jpeg|ico|js|css))
 static_files: \1
 upload: (.*\.(gif|png|jpeg|jpg|ico|js|css))

- url: .*
 script: main.application

.

import os

import webapp2
from google.appengine.ext.webapp import template

class BaseHandler(webapp2.RequestHandler):
  def render_template(self, filename, **template_args):
     path = os.path.join(os.path.dirname(__file__), 'templates', filename)
     self.response.write(template.render(path, template_args))

class IndexHandler(BaseHandler):
  def get(self):
    self.render_template('index.html', name=self.request.get('name'))

application = webapp2.WSGIApplication([
    ('/', IndexHandler),
], debug=True)
2
  • 1
    What exactly doesn't work? Commented Jan 9, 2014 at 16:06
  • It does not load index.html Commented Jan 9, 2014 at 16:10

1 Answer 1

2

In the line:

     path = os.path.join(os.path.dirname(__file__), 'templates', filename)

You're telling your code to look for your template to render in the directory "templates", not in the root directory of your app. Either use a "templates" directory, or remove it from the join.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.