Opened 15 years ago

Closed 15 years ago

Last modified 12 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: no UI/UX: no

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 15 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Matt McClanahan, 15 years ago

Triage Stage: UnreviewedAccepted

by Andrews Medina, 15 years ago

Attachment: render.patch added

comment:2 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 by anonymous, 15 years ago

Has patch: set

comment:4 by Jacob, 15 years ago

milestone: 1.1

comment:5 by Tim Graham, 15 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Kevin Kubasik, 15 years ago

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

comment:7 by Gary Wilson, 15 years ago

Resolution: fixed
Status: newclosed

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

comment:8 by Gary Wilson, 15 years ago

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

Backport of r10265 from trunk.

comment:9 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

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