Question

I am new to Google App Engine and I am attempting to create a simple multi-page application (index.htm, sites.htm, topics.htm). When I run the application without file name everything works great http://localhost:9080. But when I attempt to load a specific page http://localhost:9080/index.htm or http://localhost:9080/sites.htm or http://localhost:9080/topics.htm, I receive 404 error

Here's my app.yaml

application: msa
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /static
  static_dir: static

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

My MainHandler is as below

class MainHandler(webapp2.RequestHandler):
    def get(self):      
        path = self.request.path
        temp = os.path.join(os.path.dirname(__file__),'templates/' + path)
        self.response.write(temp + '<br />')
        if not os.path.isfile(temp):
            temp = os.path.join(os.path.dirname(__file__),'templates/index.htm')

        outstr = template.render(temp, { })
        self.response.out.write(outstr)

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

All my files have been organized in this fashion

/
/app.yaml
/index.yaml
/main.py
/static
/static/glike.css
/templates
/templates/_base.htm
/templates/index.htm
/templates/topics.htm
/templates/sites.htm

Any guidance would be much appreciated

Was it helpful?

Solution

You have to create routes: http://webapp-improved.appspot.com/guide/routing.html#simple-routes

('/', MainHandler) will only handle: /

To handle all requests use:

app = webapp2.WSGIApplication(
                          [ 
                           ('/.*', MainHandler), 
                          ], debug=True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top