Previous Page Next Page

Q&A

Q.Is there a way to tie the templates into the Django admin interface?
A.Yes. You can use the Django admin parent base_site.html in your view templates by using the following line of code to extend it:
{% extends 'admin/base_site.html' %}

Q.Is there a way to render a template to a string object so that I can parse and possibly manipulate it?
A.Yes. Django provides the django.template.loader.render_to_string (template_name, dictionary, context_instance) function that will render a template file to a string object. The render_to_string() function accepts a template file name as the first argument, a dictionary containing variables as an optional second argument, and a Context object as an optional third argument. The following code will render the someTemplate.html template file to a string:
from django.template.loader import render_to_string
render_to_string('someTemplate.html', {'name': 'Brad', 'pID': 1})

Previous Page Next Page