Make anything into a template

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#views.py
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext, Context, Template
from models import DocumentTemplate
from django.utils.safestring import mark_safe

def printable_form(self, object_id, template_id):
    """Get a `template` and drop information into it."""
    doc_template = DocumentTemplate.objects.get(pk=template_id)
    result = get_object_or_404(SomeInfo, pk=object_id)
    t = Template(doc_template.content)
    c = Context({'result': result,})
    final_html = t.render(c)
    final_html = mark_safe(final_html)
    return render_to_response('printable.html', {'final_html':final_html}, RequestContext(request))

More like this

  1. Age - custom filter by realmac 5 years, 3 months ago
  2. FieldsetForm by Ciantic 6 years, 1 month ago
  3. Jinja2 integration + application specific functions/filters/tests by hasenj 4 years, 7 months ago
  4. currency filter without using locale by andzep 2 years, 2 months ago
  5. Repeat blocks with new context / simple Jinja-like macro system by miracle2k 5 years, 9 months ago

Comments

(Forgotten your password?)