Opened 11 years ago

Closed 11 years ago

#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

Description

A lot of frameworks now allow you to do :

@something
def hello(request):
    return {}

We could apply that to django :

@render()
def hello(request):
    return 'Hello'

Returns a HttpRequest('Hello')

@render('template.html')
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'))
@render(json=True)
def hello(request):
    return {}

Change History (1)

comment:1 by Russell Keith-Magee, 11 years ago

Resolution: wontfix
Status: newclosed

Nope.

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