Difference between revisions of "User:Babbage Linden/Django/URI"

From Second Life Wiki
Jump to navigation Jump to search
(New page: Test)
 
 
Line 1: Line 1:
Test
Django has a flexible [http://docs.djangoproject.com/en/dev/topics/http/urls/ URL dispatcher] that cleanly separates URI configuration from code and allows arbitrary python extensions:
 
<pre>
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')
)
</pre>

Latest revision as of 08:05, 2 December 2008

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')
)