Basic html-mapping or url-rewriting for google appengine (python)

I am trying to rewrite the URLs for a static site in Google Appengine. I just want http://www.abc.com/about for http://www.abc.com/about.html I don’t need to rewrite things like abc.com/page?=1 or anything else. I just want to figure out how to explain, rewrite URLs for html pages.

The code I use (which does not work) is

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
import os

class MainHandler(webapp.RequestHandler):
    def get(self):
        template_values = {}

        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))


class PostHandler(webapp.RequestHandler):
    def get(self, slug):
        template_values = {}
        post_list =  { 
            'home' : 'index.html',
            'portfolio' : 'portfolio.html',            
            'contact' : 'contact.html',
            'about' : 'about.html'
        }

        if slug in post_list:
            self.response.out.write('Slugs not handled by C-Dan yet')
        else:
            self.response.out.write('no post with this slug')

def main():
    application = webapp.WSGIApplication([('/', MainHandler),('/(.*)', PostHandler)], debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()
+3
source share
1 answer

For your constructor, you want:

def main():
  application = webapp.WSGIApplication([
    ('/', MainHandler),
    ('/portfolio/', Portfolio),
    ('/contact/', Contant),
    ('/about/', About)
    ])
  util.run_wsgi_app(application)

, - http://www.abc.com/about/, "" "".

About.

class About(webapp.RequestHandler):
  def get(self):
    self.response.out.write(template.render('about.html', None))

, , , .

+4

All Articles