Fixed #20962: render() methods could raise exceptions in DEBUG

See [ticket 20962](https://code.djangoproject.com/ticket/20962).