-1

I want to add similar posts section to my blog django application in Class DetailView on detail page

class DetailView(generic.DetailView):
    model = Deal
    template_name = 'deals/detail.html'
  • Welcome to SO! Please take a look at [Ask] to understand how to post good questions. You need to be more specific. What have you tried? What isn't working? – dirkgroten Jan 12 '19 at 16:33

1 Answers1

0
class DetailView(generic.DetailView):
    model = Deal
    template_name = 'deals/detail.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data()
        context[post] = post
        return context

get_context_data method is responsible for passing the data in template . the context is a dict so you and add your key value in this dict and access it form template.

<html>
<body>
{{post}}
</body>
</html>

what ever data you added it to your context dict the you can access it from template with key.

biswa1991
  • 530
  • 3
  • 8