Monday, November 3, 2014

How to handle exceptions if RequestContext fails?

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?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d60124a-acaa-4d18-9672-05cc106808b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment