How to print page

0

I want to create a template for printing data but I'm kind of lost in how to do this, I have a print name button, it's in a table that contains the customer's name, phone number, in it it should take the id of this client and the data of the same as name, phone, address ..., and put inside the template print_page.html, which will contain some more things like logo, company name ..., someone can you tell me if you have how to do this with direct django in views or if I have to use javascript or something else?

I was trying to make direct in the views, but I ended up noting that my logic is not at all right I believe.

class PrintView(TemplateView):
    template_name = 'core/print_page.html'

    def get_context_data(self, **kwargs):
        context = super(PrintView, self).get_context_data(**kwargs)
        context['print_page'] = Client.objects.get(pk=self.pk)
        return context

I have researched but found nothing related to what I want.

Thanks in advance for any help.

    
asked by anonymous 10.05.2016 / 00:52

1 answer

0

Well, since you're going to print just one line from your database, I suggest that you use a DetailView instead of a TemplateView , so you do not have to configure the context:

class ClientPrintView(DetailView):
    model = Client
    template_name = 'core/print_page.html'

Make the template as you see fit. If you want the print window to appear right away, you can put a javascript script at the end of the template:

<script>
  (function(){
    window.print();
  })();
</script>
    
17.05.2016 / 20:07