django - Create View - access to success_url from templates -
say have:
class mycreate(createview): template_name = 'template.html' success_url = reverse_lazy('blabla') form_class = myform
and suppose in template want add back
button. lead me same page success_url
. solution override get_context_data
in mycreate
class , add {'back': self.get_success_url()}
context
.
the implications have more createviews , had create contextmixin
back
button. there other easier solution? accessing success_url
directly in template?
thanks
as can see in django (1.7) implementation of contextmixin
, must have access view
instance our templates:
def get_context_data(self, **kwargs): if 'view' not in kwargs: kwargs['view'] = self return kwargs
so can access success_url in templates:
{{ view.get_success_url }}
Comments
Post a Comment