Django-Selector is a custom url pattern parser for Django whose API is based on Luke Arno’s Selector for WSGI. It is designed to simplify the writing and reading of url patterns by providing recipes for frequently used patterns. Django-Selector’s parser ignores classic regex based url patterns, so if you require the flexibility of regexes you needn’t jump through registration hoops for a one-off url pattern. Using these named patterns in your urls.py clarifies what they are matching as well as how they are matching it:

Here’s an example of how a urls.py file might look when using django-selector:

from django.contrib import admin from django.conf import settings import dselector admin . autodiscover () parser = dselector . Parser () urlpatterns = parser . patterns ( '' , ( r'admin/(.*)!' , admin . site . root ), ) urlpatterns += parser . patterns ( 'myblog' , ( r'blog/{page:digits}/' , 'list' , {}, 'blog-list' ), ( r'blog/{slug:slug}/' , 'detail' , {}, 'blog-detail' ), ( r'archive/{year:year}/' , 'archive' , {}, 'blog-year' ), ( r'archive/{year:year}/{month:month}/' , 'archive' , {}, 'blog-month' ), ( r'archive/{year:year}/{month:month}/{day:day}/' , 'archive' , {}, 'blog-day' ), ( r'comment/post/{content_type:slug}/{id:digits}/' , 'comment_post' , {}, 'comment-post' ), ) if settings . DEBUG : urlpatterns += parser . patterns ( 'django.views.static' , r ( 'media/{path:any}' , 'serve' , { 'document_root' : './media/' }), )

The primary way of denoting url parts with django-selector’s parser is via the named patterns syntax: {name:pattern} . This is parsed into a regular expression looking roughly like:

'(?P<name> %s )' % ( pattern_definition )

Refer to the List of builtin named patterns for a description of all default patterns. You may optionally leave out the pattern, which will match against the segment pattern:

( r'archive/{year}/{month:month}/{day}/' , archive , {}, 'blog-day' )

Beyond these preprocessing steps, django-selector’s parser.patterns operates as the standard django.conf.urls.defaults.patterns .