• Skip to primary navigation
  • Skip to main content
  • Skip to footer
Sproutee Inc

Sproutee Inc

Websites, Ecommerce, SEO G Suite

  • Portfolio
  • Pricing
  • Contact

Pretty URLs in Google App Engine

You are here: Home / Web Design & Development / Pretty URLs in Google App Engine

Today I implemented so-called ‘pretty urls’ for my Google App Engine application. While my URL structure was reasonably clean before this work, I was inspired to make improvements after attending ThinkVisibility and particularly after talks by Rob Lee and Tom Smith. While it wasn’t too painful to track down information on how I might achieve Pretty URLs in GAE, it did take a little trial and error to get running, so I thought it worth a post. Indeed, if readers have suggestions for a more elegant solution, I welcome comments.

What is a Pretty URL? A Pretty URL is a URL designed to be ‘hackable’, or human-readable. Ideally, users should be able to intuit a Pretty URL address, and likewise a Pretty URL might serve as a ‘bread crumb’ or ‘sign post’ indicating to the user where s/he is in the application. Compare, for example, a less than fetching URL (a) with a more pleasing example (b):

a) mysite.com/mycategory?myparam=an_entity_id
b) mysite.com/mycategory/an_entity_id

Example ‘b’ is just the sort of URL I desired; purdy, ain’t she?

I chose to use my WSGIApplication’s constructor to point Pretty URLs at appropriate Handlers:

application = webapp.WSGIApplication([('/category/.*', CategoryHandler)], debug=True)

The ‘category’ is associated with a particular Handler, while the ‘.*’ regex matches the UID of the entity to be retrieved, which is passed on the URL. In the Handler’s get function I retrieve the path instance variable include on the Request object, which returns a substring of the URL between the host name and query parameters. I then substring the path string in order to retrieve the key of the entity requested by the user:

path = str(self.request.path)
key = path[6:len(path)]
if key:
#Retrieve the entity and shoot back a response

This appears to be working well and as expected; I’m certainly blushing every time I lay eyes on one of my app’s sweet little URLs.

(Readers may wish to view Google’s doc on URL config; note if you try copying and pasting the syntax in their example you’ll get exceptions, hence the trial and error aspect of my implementation.)

  • Share
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)

23/03/2009 by Meg Smitley in Web Design & Development

Website Packages

Put your best foot forward.

Attract more leads with a professional website

Get started

Footer

Links

  • Home
  • About
  • Blog

Services

  • Free website audit
  • Web design & websites
  • Ecommerce websites

 

  • Marketing & SEO
  • G Suite
  • Hosting
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
Copyright © 2023 Sproutee Inc · Privacy policy · Terms & conditions · Sitemap
This site tracks visits anonymously using cookies. We use this information to improve your experience of our site. You can opt-out if you choose.Accept Reject Read More
Privacy Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT