Skip to content

Instantly share code, notes, and snippets.

@starenka
Forked from dg/gist:1009307
Created June 5, 2011 19:45
Show Gist options
  • Save starenka/1009323 to your computer and use it in GitHub Desktop.
Save starenka/1009323 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"

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

In template:

    <p><a href="{% url articles.views.detail article.year article.id %}">The Article</a></p>
  • Regular expression is hard to read. # Does it?
  • Any change of URL means to change some templates. #As well as in Nette (unless the n macro is not RBM)
  • Redirect to the prefered URL must developer provide itself. #What redirect?

Nette Framework

In bootstrap.php

    $router[] = new 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 is done automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment