Hello,
I'm a kind of newbie with Django and recently I faced the following
problem.
I wrote custom context processor, that adds in RequestContext
'base_template' variable. It works fine but in some views I'd like to
override somehow this variable. I can do this with default shortcuts
function like render or render_to_response cause RequestContext
instance is updated with supplied context dictionary inside
render_to_string function as 'context_instance.update(dictionary)'.
But if I use class based generic views their render_to_response method
behaves differently.
e.g. I override get_context_data_method this way:
def get_context_data(self, **kwargs):
context = super(EditLayout, self).get_context_data(**kwargs)
context['base_template'] = "layout_edit.xhtml"
context["edit_mode"] = True
return context
but still get default value of 'base_template' (set in my context
processor ) in actually rendered template.
I found this workaround:
def render_to_response(self, context, **response_kwargs):
return render(self.request, self.get_template_names()[0],
context)
But I think that must be some better way to do it. Do I miss something?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.