• 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: Routes in Google App Engine

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

Pretty URLs are an essential element of web applications. Pretty URLs are helpful to users, influential for SEO and implementations may enhance the beauty (and so the extensibility and maintainability) of a code base. This is superbly achieved in Google App Engine using Rodrigo Moraes’ App Engine recipe for URL mapping using Routes.

I discussed in a previous post how I used a basic implementation of GAE’s WSGIApplication for Pretty URL mapping. While this approach served my initial needs, it required a lot of extra logic to read params from incoming URLs and did not elegantly handle URLs invoked in an AJAX call (i.e. logic was need in the handler to interpret the URL and delegate to the appropriate action). My goal was to implement a Pretty URL mapping scheme that allowed me to:

  • configure URL mappings in one place only
  • gracefully pass params on URLs
  • invoke actions contained in my handlers

Happily, I stumbled upon Moraes’ recipe; it was a snap to follow the very clear directions to import Routes and override the WSGIApplication. Further support from the Routes documentation allowed me to quickly and easily meet all my Pretty URL goals.

All URL mappings are configured in routing.py. Params passed on URLs are discretely mapped and retrieved. For instance this mapping accepts a param named ‘id’ and hits a handler in views.py called ‘MyHandler’:

map.connect('handler/:id', controller = 'views:MyHandler')

In views.py, ‘id’ is picked up as an argument of the get() method:

class MyHandler(ParentHandler):def get(self, id): ...

How cool is that?! Crisp and clean and no caffeine. It gets better.

I can also map to a handler and an action. This is particularly handy for my api.py, which accepts AJAX requests. With this mapping the correct handler’s action is invoked without any messy delegation at the top of my api.py:

map.connect('api/handler/action', controller = 'api:MyHandler', action = 'action')

How great is this? Pretty URLs and cleaner code. Yes, I’ve added the Routes resources and Moraes’ overridden WSGIApplication, but the separation of mapping logic from other aspects of the application pleases me and I believe makes for a more robust code base. Not to mention, I learned a new thing! Thanks Mr Moraes, my URLs got pulchriTUDE!

  • 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)

17/06/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