smarturls

A URL construction helper for Django
Download

smarturls Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Amit Upadhyay
  • Publisher web site:
  • http://amitu.com

smarturls Tags


smarturls Description

smarturls is an app that comes with a library of regularly used regular expression patterns to easy regex creation for django URLs. The library can be extended by using Django setting system.Install smarturls easy_install smarturlsExample usageThis is how normal django urls.py looks like:from django.conf.urls.defaults import *urlpatterns = patterns('', ('^book/(?P< bookid >\d+)/$', 'some.view'), ('^author/(?P< author_name >+)/$', 'some.other.view'), ('^year/(?P< year >\d{4,4})/$', 'year.view'), ('^year/(?P< year >\d{4,4})/(?P< month >\w+)/$', 'month.view'),)This is how it looks like with smarturls:from django.conf.urls.defaults import *from smarturls import surlurlpatterns = patterns('', surl('/book/< int:bookid >/', 'some.view'), surl('/author/< slug:author_name >/', 'some.other.view'), surl('/year/< int4:year >/', 'year.view'), surl('/year/< int4:year >/< word:month >/', 'month.view'),)Custom patternsExisting patterns can be overwritten and new ones can be defined by defingin the django setting SURL_REGEXERS.Eg, in settings.py:SURL_REGEXERS = { "slug": "\w*", # overwrite slug: always start with alphanumeric "username": "\w+" # now you can use /author// etc}Default PatternsBy default smarturls comes with the following patterns:- int: \d+- int2: \d{2,2}- int4: \d{4,4}- word: \w+- slug: +- digit: \d{1,1}- username: +Product's homepage


smarturls Related Software