0

I have "static" javascript templates I want to serve with my Django application. Usually you put them in the static folder and that's it. The problem here is the templates aren't really static, they are jade(pyjade) templates that need to be pre-compiled.
My plan is having the templates inside a sub-directory of the app's templates dir, lets call it jstemplates, and then serve them from the urls.py file like this:

...
url(r'^jstemplates/(?P<template>.*)', TemplateView.as_view(template_name=<captured_name>)),
...

but how can I get the captured template name?

olanod
  • 30,306
  • 7
  • 46
  • 75

1 Answers1

0

Thinking it better, I suppose the captured attribute won't be available until view's instantiation so I made a sub-class of TemplateView called JsTemplateView.

class JsTemplateView(TemplateView):
    def get_template_names(self):
        return "jstemplates/%s.jade" % self.kwargs['template']

and added the corresponding line in urls.py url(r'^jstemplates/(?P<template>.*)', JsTemplateView.as_view()

olanod
  • 30,306
  • 7
  • 46
  • 75