greetings, i have created a template loader to grab templates from the database:
from django.template import TemplateDoesNotExist try: from myproject.editor.models import Layout except: Layout = None def load_template_source(name, template_dirs=None): """ Loads templates from the database instead of the filesystem. """ try: t = Layout.objects.get(name=name) return (t.content, 'loader:%s' % name) except: raise TemplateDoesNotExist, name pass load_template_source.is_usable = Layout is not None and then we have the view to grab the data from the database and put it all together to make it work: def paint(request, slug): p = get_object_or_404(Page, slug=slug) pp = PagePart.objects.get(page_id=p.id) t = template.Template(pp.content) pp.content = t.render(request) lay = Layout.objects.get(pk=p.layout_id_id) return render_to_response(lay.name, {'content': pp}, RequestContext(request)) this has worked flowlessly for us until i tried to use a custom template tag to display information within one of the database templates. i have narrowed the problem down to the loader or the view, since i can use the custom template tag with a file system template but it does not work with the database templates. here is the tag: from django import template from myproject.editor.models import Project register = template.Library() class GetProject(template.Node): def __init__(self, arg1, arg2): self.varname = arg1 self.slug = arg2 def render(self, context): project = Project.objects.get(slug=self.slug) t = template.Template() context[self.varname] = t.render(project) return '' class DoGetProject: """ {% get_project as project %} """ def __init__(self, tag_name): self.tag_name = tag_name def __call__(self, parser, token): bits = token.contents.split() if len(bits) != 4: raise template.TemplateSyntaxError, "'%s' tag takes three arguments" % bits[0] if bits[1] != "as": raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0] return GetProject(bits[2], bits[3]) register.tag('get_project', DoGetProject('get_project')) from the template level you call {% get project as fp projectslug % where fp is the name of context variable that will be used at the template level and "projectslug" is the slug of the project. thus you can display {{ fp.name }} or {{ fp.description }} etc. i suspect that the problem lies in the view, but i cannot seem to see where i might have gone wrong with the code. i have made various changes to it, like: t = template.Template(project.description) context[self.varname] = t.render(context) but to no avail. any help would be greatly appreciated. saludos, steve --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---