Skip to content

Instantly share code, notes, and snippets.

@artschwagerb
Last active April 18, 2016 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artschwagerb/e6b8e8193e229511e28f8ed2847e4678 to your computer and use it in GitHub Desktop.
Save artschwagerb/e6b8e8193e229511e28f8ed2847e4678 to your computer and use it in GitHub Desktop.
Django Templates
from django.shortcuts import render_to_response, get_object_or_404, render
from django.template import RequestContext, loader, Template
from myapp.models import Model_name
# Template from app directory (lumber), passing in "data"
doc_template = loader.get_template('lumber/%s/result.txt' % ("my_label"))
doc_context = RequestContext(request, {
'data': result['source'],
})
doc_html = doc_template.render(doc_context)
# Template from app model(TreeType), using the template HTML found in the "template_web" TextField, passing in "data"
tree_label = "my_label"
s = TreeType.objects.get(label=tree_label).template_web
# ^ using the "label" to find the object
doc_template = Template(s)
doc_context = RequestContext(request, {
'data': result['source'],
})
doc_html = doc_template.render(doc_context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment