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/
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.
Why would anyone have two URL schemas? wth .html and without? You could always
write a middleware in Django that would handle the redirects for you, 5 lines
of code to apply it globally but I see no point in such functionality
whatsoever.
Django has a bultin middleware (enabled by default though customizable via
settings) that would dynamically append slash ('/') to any URL without trailing
slash that returns 404.
For me these systems are perfectly equivalent in the features compared it just
comes down to personal preference (having normal ugly regexps or custom more
readable notation) for parameter definitions.