Automatically create urls for templates in a directory

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.conf import settings
from django.conf.urls.defaults import patterns, url, include
from django.views.generic.simple import direct_to_template


urlpatterns = patterns('',
    # Example:
    # (r'^news/', include('news.foo.urls')),
)

if getattr(settings, "DEBUG", False):
    # Load template urls for reference
    def h(*args, **kwargs):
        t = "%s/%s" % (kwargs['base'], kwargs['template'])
        if t.endswith('/'):
            t = "%sindex.html" % t
        kwargs['template'] = t
        return direct_to_template(*args, **kwargs)

    urlpatterns = patterns('',
        url(r"^(?P<base>html)/(?P<template>.*)$", h),
    ) + urlpatterns

More like this

  1. Automatic urls for static pages by jibbolo 3 years, 5 months ago
  2. direct to template from a subdir by Scanner 5 years, 6 months ago
  3. DaGood breadcrumbs by drozzy 5 years, 3 months ago
  4. Integrating Django with ToofPy by Siddhi 6 years, 9 months ago
  5. Generic AJAX app by Rupe 4 years, 10 months ago

Comments

jumpifzero (on November 4, 2011):

Interesting! Thanks :)

#

(Forgotten your password?)