I am slightly trying to abuse render_view()
to dynamically look up viewlets to render inside my main view. However, the framework is robust and my abusing attempts have utterly failed. The problem is specifically: when I call render_view() and manually pass in context, I don't know how to look up this context in the target view.
context
through render_view()context
Is it possible to pick up passed in context somewhere? Or is there a better alternative to render subviews (viewlets?) in Pyramid, instead of abusing render_view()
@view_config(route_name='admin', renderer='admin/admin.html', permission='view')
def admin(request):
# Herer request.context = Admin
p = AdminPanel()
rendered_panel = render_view(context=p, name="admin_panel", secure=True, request=request)
return dict(panels=rendered_panel)
@view_config(context=AdminPanel, name="admin_panel", renderer='string', permission='view')
def panel(request):
# XXXXXXXXXXXXX
# This is the original request.context Admin, not one I passed in render_view() above
# XXXXXXXXXXXXX
context = request.context
....
Apparently you can have context as the first argument of view function. Somehow I had missed this as there were not too many examples of this sort:
@view_config(context=AdminPanel, name="admin_panel", renderer='string', permission='view')
def panel(context, request):