Pretty URLs in Google App Engine

余生颓废 提交于 2019-11-28 08:28:51

This is a cool question. I figured out how to do it for python as well.

app.yaml:

- url: /test/(.*)
  script: test.py \1

test.py:

#!/usr/bin/env python

import sys

def main():           
  for arg in sys.argv:
     print arg

if __name__ == '__main__':                               
  main()

You need to configure the application (see here). In other words, you need to "wire" the patterns you want.

From the manual, an example:

<servlet-mapping>
    <servlet-name>redteam</servlet-name>
    <url-pattern>/red/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>blueteam</servlet-name>
    <url-pattern>/blue/*</url-pattern>
</servlet-mapping>
Jeroen

Try UrlRewriteFilter: http://tuckey.org/urlrewrite/ (or github repo) it is a plain ol' Java EE filter, so it should work.

Save yourself some time and use Restlet. You can do exactly this and I've done this in two different projects. It's quite straight forward. If you need some help, let me know.

I would probably use PrettyFaces, http://ocpsoft.com/prettyfaces/ which allows you to do URL-mappings directly on top of an existing application.

You just configure something like this in the pretty-config.xml file:

<url-mapping>
   <pattern value="/my/pretty/url" />
   <view-id value="/my/existing/url" />
</url-mapping>

Or if you want to rewrite parameters, you can do this:

<url-mapping>
   <pattern value="/my/pretty/url/#{param}" />
   <view-id value="/my/existing/url" />
</url-mapping>

And this means that any urls (inbound) now become:

/my/pretty/url/value -> /my/existing/url?param=value

And outbound your URLs will look like this in HTML pages and in redirects:

/my/existing/url?param=value -> /my/pretty/url/value

So it's easy to add on to your current apps.

Here is another project that I think may really help you:

It's called restful-gwt... it's pretty slick too: http://code.google.com/p/restful-gwt/

Good luck!

This is the best approach I found so far for implementing URL rewrite GAE Python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!