From e8969ccc4a5f01846c2ce24bfbfc1f4fda76983e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 12 Feb 2013 16:01:17 +0100 Subject: [PATCH] prefix urls --- videopdf/urls.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/videopdf/urls.py b/videopdf/urls.py index 4e779e4..d5fcca7 100644 --- a/videopdf/urls.py +++ b/videopdf/urls.py @@ -8,32 +8,39 @@ from django.conf import settings from django.contrib import admin admin.autodiscover() +def p(url): + if settings.PREFIX: + url = r'^%s/%s' % (settings.PREFIX[1:], url) + else: + url = r'^' + url + return url + urlpatterns = patterns('', # Examples: # url(r'^$', 'videopdf.views.home', name='home'), # url(r'^videopdf/', include('videopdf.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: - url(r'^admin/doc/', include('django.contrib.admindocs.urls')), + url(p('admin/doc/'), include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: - url(r'^admin/', include(admin.site.urls)), + url(p('admin/'), include(admin.site.urls)), ) if settings.DEBUG: urlpatterns += patterns('', - (r'^data/(?P.*)$', 'django.views.static.serve', + (p('data/(?P.*)$'), 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), - (r'^static/(?P.*)$', 'django.views.static.serve', + (p('static/(?P.*)$'), 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}), ) urlpatterns += patterns('item.views', - (r'^$', 'index'), - (r'^add$', 'add'), - (r'^save$', 'save'), - (r'^([A-Z0-9].*)/$', 'item'), - (r'^([A-Z0-9].*)/chunk$', 'chunk'), - (r'^([A-Z0-9].*)/(.+.pdf)$', 'pdf'), - (r'^([A-Z0-9].*)$', 'item'), + (p('$'), 'index'), + (p('add$'), 'add'), + (p('save$'), 'save'), + (p('([A-Z0-9].*)/$'), 'item'), + (p('([A-Z0-9].*)/chunk$'), 'chunk'), + (p('([A-Z0-9].*)/(.+.pdf)$'), 'pdf'), + (p('([A-Z0-9].*)$'), 'item'), )