On Friday, 22 November 2013 13:13:46 UTC, Timothy W. Cook wrote: > > Lucas, > > On Fri, Nov 22, 2013 at 9:58 AM, Lucas Magnum > <lucasm...@gmail.com<javascript:>> > wrote: > > Timothy, > > The "get_context_data" is called in get method, once you override it > > "get_context_data" isn't called anymore. > > > > Right. So my thought process was that if I override it and place > additional information there it would be available in the template. > Obviously my thinking is incorrect, but where? >
Lucas means that by overriding get(), you've removed the place where `get_context_data` is originally called. You could certainly do it within your own `get()` function, simply with `context = self.get_context_data()`, but you might as well keep it within `get()` as you do below. > So how do I add variables to the context so that I can display their > value in the template? > > In this case I want to get the title of the paper and display it in > the template. If I do this in get(): > > def get(self, request, *args, **kwargs): > paper = Paper.objects.filter(id=kwargs['pk']) > kwargs['title'] = paper[0].title > print('Title: ',kwargs['title']) > form = self.form_class(initial=self.initial) > return render(request, self.template_name, {'form': form}) > > IT prints it to the terminal okay. But (using DjDT) I do not see > where 'title' was added to kwargs. Not do I see it in the template > context. > > Any idea what I am missing or how to do this? > You've added it to kwargs, but you haven't passed kwargs as the template context - you've simply hard-coded that to `{'form': form}`. -- DR. -- 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+unsubscr...@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/c3e1b7a3-1e6a-4eed-8176-5e2da20d1c36%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.