English 中文(简体)
Basic html-mapping or url-reeven for google appengine (python)
原标题:Basic html-mapping or url-rewriting for google appengine (python)

I m trying to rewrite urls for a static site on Google Appengine. I only want http://www.abc.com/about for http://www.abc.com/about.html I don t need rewriting for stuff like abc.com/page?=1 or anything. I just wanna figure out how to explicity rewrite urls for html pages.

目前使用的Im代码(固定工作)——

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()
最佳回答

贵方希望:

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

这意味着任何人都到,他们将前往你的约手。

之后,你们必须做一手。

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

我不熟悉你的编码风格,但我刚才表明,我在所有项目中为我工作。

问题回答

暂无回答




相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签