Pylons/pyramid — Issue #448: Pyramid 1.2: Loosing context
Author: danosaure
Created: 2012-02-24 23:10:41+00:00
State: open

I'm not sure if this is a bug or not, but here how it goes.

```python
@view.view_config(context=httpexceptions.HTTPForbidden)
def http_forbidden(context, request):
if (condition):
return renderers.render_to_response('tmpl1.mako', {}, request=request)
return renderers.render_to_response('tmpl2.mako', {}, request=request)
```

In my templates, the `context` is not `httpexceptions.HTTPForbidden` anymore, but is my `root_factory` instance.

The work-around I had to do is to use `override_renderer`:

```python
@view.view_config(context=httpexceptions.HTTPForbidden, renderer='tmpl2.mako')
def http_forbidden(context, request):
if (condition):
request.override_renderer = 'tmpl1.mako'
return {}
```

I wonder if I should have gotten the correct context in the first way to do it (which seems more natural to me). I think that if wouldn't have happened if it was a view for a route_name and not a context.

Thanks for any insights.