How to handle exceptions if RequestContext fails?

23 views
Skip to first unread message

Daniel Grace

unread,
Nov 3, 2014, 2:09:58 PM11/3/14
to django...@googlegroups.com
Say I have the following code:

logger = logging.getLogger(__name__)

def render_error(scr_msg, err_msg, context):
    logger.debug(err_msg)
    return render_to_response('error.html', {'message': scr_msg}, context)
...
def some_view():
    try:
       context = RequestContext(request)
        ...
    except Exception as e:
        return render_error('An error occured whilst showing some view.', e.args[0], context)

... then how do I handle the exception without a context?  Should I use the render function instead of render_to_response in the exception handler?

Collin Anderson

unread,
Nov 5, 2014, 12:09:07 PM11/5/14
to django...@googlegroups.com
Hi Daniel,

Would it work to pass in an empty Context? You could also as you say, try using render() to see if it would work.

Collin

Reply all
Reply to author
Forward
0 new messages