Getting Routed

Routing confuses me.  But not always.

The app we’re working on lately combines Django and Angular.  Both great frameworks that function similarly in some ways (injecting templates directly into the html, even using the same curly brackets), but very different in others.  Like routing.

Or maybe it’s just me.  I find Angular (1.x) routing really straightforward to use.  You’ve got your routeProvider, can grab GET parameters off the routeParams object, and just set up your .when() calls.  Although, as a short aside, I did find one gotcha with Angular.  I thought I was being so clever- I wanted to set up a default route using .otherwise() to make a 404 type page for the app.  So if a user goes to a url that doesn’t exist, they get a nice message that they’re lost and a link to a sitemap type screen.  However, the default route will show on first display of the app, so that was kind of tricky.  I didn’t want a 404 to be the first thing people see! So I tried to make a .when(‘/’) route, and have .otherwise point to that.  This is not a good idea.  It created an infinite loop that crashed Chrome (unrecoverable- had to ctrl-alt-delete out of it).  So don’t do that!

But in general, Angular’s routes are really nice to use.  I had (have) more trouble with setting up Django’s routing.  Maybe it’s my (rational) fear of regexes, but the file reads like Greek to me.  I can get simple routes working- but that’s mainly what I was able to tweak after doing the default Django blog tutorial.  The concepts behind Django routing seem to make sense, it’s just the practice of getting them to work (without spending hours of trial and error) that’s taking quite a bit longer to learn.

But in all, both are great ways of handling the request/response of the web.  Set up one section of routing (or two with Django- you need the as well) and let the framework do the heavy lifting!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s