Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10120 closed (fixed)

Possible mistake? in "render_to_response()" Example / NO return value

Reported by: vl4dt Owned by: Kevin Kubasik
Component: Documentation Version: 1.0
Severity: Keywords: render_to_response possible mistake mispelling error missing return function value no kkmegapatch
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

render_to_response() - Example - No return value

Possible mistake

found at:
Django shortcut functions: render_to_response() - Example

First piece of code:

from django.shortcuts import render_to_response

def my_view(request):
    # View code here...
    return render_to_response('myapp/index.html', {"foo": "bar"},
        mimetype="application/xhtml+xml")

equivalent to:

from django.http import HttpResponse
from django.template import Context, loader

def my_view(request):
    # View code here...
    t = loader.get_template('myapp/template.html')
    c = Context({'foo': 'bar'})
    r = HttpResponse(t.render(c),
        mimetype="application/xhtml+xml")

Possible mistake:
The second fragment does not "return" anything, or does return "r"?

Maybe this line at the end of the function is missing:

    return r

or this line:

    r = HttpResponse(t.render(c),
        mimetype="application/xhtml+xml")

was intended to be:

    return HttpResponse(t.render(c),
        mimetype="application/xhtml+xml")

I am new to Python and Django so if I am just ignorant on Python please point why I am wrong.

Postdata:
Excelent framework and documentation, I come from Rails and am really impressed by the quality of Django and how complete and comprehensive the documentation is, keep doing that great work.
Excuse my bad english.

Attachments (1)

render.patch (500 bytes) - added by Andrews Medina 8 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 8 years ago by Matt McClanahan

Triage Stage: UnreviewedAccepted

Changed 8 years ago by Andrews Medina

Attachment: render.patch added

comment:2 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 Changed 8 years ago by anonymous

Has patch: set

comment:4 Changed 8 years ago by Jacob

milestone: 1.1

comment:5 Changed 8 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:6 Changed 8 years ago by Kevin Kubasik

Keywords: kkmegapatch added
Owner: changed from 1.0.2 to Kevin Kubasik

comment:7 Changed 8 years ago by Gary Wilson

Resolution: fixed
Status: newclosed

(In [10265]) Fixed #10120 -- Added a return to a doc example, patch from andrews.

comment:8 Changed 8 years ago by Gary Wilson

(In [10266]) [1.0.X]: Fixed #10120 -- Added a return to a doc example, patch from andrews.

Backport of r10265 from trunk.

comment:9 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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