Skip to content

Instantly share code, notes, and snippets.

@dg
Created June 5, 2011 19:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dg/1009307 to your computer and use it in GitHub Desktop.
Save dg/1009307 to your computer and use it in GitHub Desktop.
Routing in Django verus Nette Framework

DJANGO

In urls.py

# urls like "articles/2011/tutorial03" or "articles/2011/tutorial03.html" or "articles/2011/tutorial03.htm"

urlpatterns = patterns('',
    (r'articles/(?P<year>\d+)/(?P<item>[^/]+)(?:\.htm(?:l)?)?/?\$', 'articles.detail'),
)

In template:

<p><a href="{% url articles.views.detail article.year article.id %}">The Article</a></p>
  • Regular expression is hard to read.
  • Any change of URL means to change some templates.
  • Redirect to the prefered URL (e.g. articles/2011/tutorial03.htm -> articles/2011/tutorial03) must developer provide itself.

source: https://docs.djangoproject.com/en/1.3/intro/tutorial03/

Nette Framework

In bootstrap.php

$router[] = new Route('articles/<year \d+>/<item>[.htm[l]]', 'Articles:detail');

In template:

<p><a n:href="Articles:detail $article->year, $article->id">The Article</a></p>
  • Route mask is easy to read.
  • Any change of URL means to change one line in bootstrap.php.
  • Redirect to the prefered URL (e.g. articles/2011/tutorial03.htm -> articles/2011/tutorial03) is done automatically.
@Almad
Copy link

Almad commented Jun 14, 2011

@littlemaple: Oh, I thought you were thinking abotu canonical URI.

I agree there should be one preferred way, this is why I am using only reverse() with named routes, althrough I can view others as "aliases", in the same way there should be one canonical URI, but content can be displayed under variety of non-canonical ones.

Rest is nette vs. django flame (OK, some PHP vs. Python flame included) I will not dwell into, as I don't like either of those much; however, I'd say that while working with GET params is not very comfortable in Django, I agree with the distinction between parameters and application routing. GET should be really parameters and not resource identificators...and also because of funny http caching mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment