Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#10120 closed (fixed)

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

Reported by: vl4dt Owned by: kkubasik
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 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by mattmcc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by andrews

comment:2 Changed 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:3 Changed 6 years ago by anonymous

  • Has patch set

comment:4 Changed 6 years ago by jacob

  • milestone set to 1.1

comment:5 Changed 6 years ago by timo

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 6 years ago by kkubasik

  • Keywords kkmegapatch added
  • Owner changed from 1.0.2 to kkubasik

comment:7 Changed 6 years ago by gwilson

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:8 Changed 6 years ago by gwilson

(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 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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