User:Babbage Linden/Django/URI
Jump to navigation
Jump to search
Django has a flexible URL dispatcher that cleanly separates URI configuration from code and allows arbitrary python extensions:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
from presence.dispatcher import HttpMethodDispatcher
region_dispatcher = HttpMethodDispatcher('presence.rest', 'region')
uuid = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
urlpatterns = patterns('',
# Example:
# (r'^regionpresence/', include('regionpresence.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),
(r'^region/(?P<region_id>%s)/$' % uuid, region_dispatcher),
(r'^region/(?P<x>[0-9]+)/(?P<y>[0-9]+)/$', 'presence.rest.location'),
(r'^region/(?P<region_id>%s)/neighbors/$' % uuid, 'presence.rest.neighbors'),
(r'^estate/(?P<estate_id>[0-9]+)/$', 'presence.rest.estate')
)