Docs + unit tests for Response, closes #821

This commit is contained in:
Simon Willison 2020-06-08 20:32:10 -07:00
commit db660db463
4 changed files with 86 additions and 1 deletions

View file

@ -405,6 +405,15 @@ class Response:
content_type="text/plain; charset=utf-8",
)
@classmethod
def json(cls, body, status=200, headers=None):
return cls(
json.dumps(body),
status=status,
headers=headers,
content_type="application/json; charset=utf-8",
)
@classmethod
def redirect(cls, path, status=302, headers=None):
headers = headers or {}