Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

24 lines (20 sloc) 0.606 kB
import functools
import json
from django import http
def json_view(f=None, status_code=200):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kw):
response = func(*args, **kw)
if isinstance(response, http.HttpResponse):
return response
else:
return http.HttpResponse(
json.dumps(response),
content_type='application/json',
status=status_code)
return wrapper
if f:
return decorator(f)
else:
return decorator
Jump to Line
Something went wrong with that request. Please try again.