#21522 closed New feature (wontfix)

Add rendering decorators

Reported by: anonymous Owned by: nobody
Component: Core (Other) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


A lot of frameworks now allow you to do :

def hello(request):
    return {}

We could apply that to django :

def hello(request):
    return 'Hello'

Returns a HttpRequest('Hello')

def hello(request):
    return {}

Is an alternative syntax for return render('template.html', {}). It's more declarative, and removes the boiler plate code from the function body where only the view logic now appears.

Possiblities :

@render('template.xml', mimetype='application/xml')
def hello(request):
    return {}

@render('template.html', code=404)
def hello(request):
    return {}

# this will return HttpRequest(json.loads({}), mimetype='application/json'))
def hello(request):
    return {}

Change History (1)

comment:1 Changed 23 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed


The Golden rule of decorators -- they shouldn't modify the prototype of the function that they're decorating. If an undecorated function returns a HttpResponse, then so should the decorated function.

Completely aside from this philosophical argument -- I simply don't see any advantage in readability or reusability in:

@render('template.html', code=404)
def hello(request):
    return {}

compared to:

def hello(request):
    return render('template.html', {}, code=404)

On a historical note - this has been proposed many times in the past, and been rejected for the same reasons.

So - marking wontfix.

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