Django makes a few shortcuts available to save us from repetitive, common coding.
Since it's pretty common to create a context, load a template, render the template, and then return the rendered string as an HTTP response, Django provides a shortcut at django.shortcuts.render_to_response
to do this quickly.
In your mycompany/press/views.py
file, add this line to the top of the file to import the render_to_response
function:
from django.shortcuts import render_to_response
In the same file, edit the latest
function to look like this:
def latest(request): ''' Returns information on the latest press release ''' p = PressRelease.objects.latest() return render_to_response('press/latest.html', { 'press': p, })
Instead of loading a template file, creating a context, and rendering the template with the context, we simply use the render_to_response
function that takes a template as its first argument and context as its...