Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#18498 closed Uncategorized (worksforme)

you still need to import http response after changing to render_to_response as a shortcut

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


you still need to import http response after changing to render_to_response as a shortcut. The documentation for part 3 says the opposite:

"It's a very common idiom to load a template, fill a context and return an HttpResponse object with the result of the rendered template. Django provides a shortcut. Here's the full index() view, rewritten:

from django.shortcuts import render_to_response
from polls.models import Poll

def index(request):

latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})

Note that once we've done this in all these views, we no longer need to import loader, Context and HttpResponse.

The render_to_response() function takes a template name as its first argument and a dictionary as its optional second argument. It returns an HttpResponse object of the given template rendered with the given context."

The other views (detail, results, vote) all use HttpResponse. If we no longer import httpresponse, the code will not run

Change History (2)

comment:1 Changed 6 years ago by Aymeric Augustin

Resolution: worksforme
Status: newclosed

The section you quote says once we've done this in all these views. Isn't that clear enough?

comment:2 Changed 6 years ago by anonymous

Ah yes I see what you mean. I guess you are right - it is clear but I missed it the first time. Maybe you could be more explicit telling the person to change it on each view explicitly, but I guess that is being nitpicky.

Note: See TracTickets for help on using tickets.
Back to Top