Render a Django HTML Template to a PDF file // Django Utility // CFE // Render_to_PDF

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ต.ค. 2024

ความคิดเห็น • 115

  • @kaustavsengupta8757
    @kaustavsengupta8757 5 ปีที่แล้ว +5

    It's more than 2 years and still this video is gold. You are still best Django instructor in TH-cam so far. Kudos to you justin

  • @maizorin22
    @maizorin22 7 ปีที่แล้ว +10

    I was about to find out about how to generate a PDF from HTML with Django and as I'm following your channel, this just appears like magic! thank you so much!

  • @ДмитрийГречкин-з5е
    @ДмитрийГречкин-з5е 3 ปีที่แล้ว

    I've just watched this video and my mind got blown after realisinz how much time I could really waste on finding out another solution... Subscribed!

  • @akhadtop2067
    @akhadtop2067 3 ปีที่แล้ว

    The best video for rendering pdf in entire youtube 🔥

  • @Empeiro
    @Empeiro 4 ปีที่แล้ว +1

    Sencillo, facil de entender, justo lo que se necesita! Nice!!!! Thanks a lot! I was searching this for almost a week! ☺

  • @csandreas1
    @csandreas1 4 ปีที่แล้ว

    you make django look more awesome. Great vid

  • @noumab6490
    @noumab6490 5 ปีที่แล้ว +12

    Thank you very much for this video :)
    I've a question, in the html template ,how can we display unicodes caracters (like arabic caracters ,japanese) with ISO-8859-1 it displays like a black squares. Thanks again

    • @what-the-code
      @what-the-code 2 ปีที่แล้ว

      Have u got solution? Plz share

    • @dgiri2333
      @dgiri2333 ปีที่แล้ว

      ​@@what-the-code you have to load font family at template its revolve a issue

  • @AlotaibiAbdulAziz
    @AlotaibiAbdulAziz 3 ปีที่แล้ว

    Very nice .. Thank you. I hope to provide lessons for the DMS system. Scanning documents from the fax machine and converting them to pdf

  • @AsaduzzamanSohel
    @AsaduzzamanSohel 7 ปีที่แล้ว +3

    On the render_to_pdf function, change the encoding from "ISO-8859-1" to "utf-8" for Bangla language. But not render properly. How can I do that?

    • @what-the-code
      @what-the-code 2 ปีที่แล้ว

      Have u got solution? Plz share

  • @GonzoOfGaming
    @GonzoOfGaming 7 ปีที่แล้ว

    Wow dude thanks! This worked great when linking to a function call in Django Admin!

    • @CodingEntrepreneurs
      @CodingEntrepreneurs  7 ปีที่แล้ว

      +GonzoOfGaming sweet! You're welcome!

    • @rutujamurge7713
      @rutujamurge7713 3 ปีที่แล้ว

      was your images displayed when you rendered from html to pdf

  • @agranshuaggarwal3947
    @agranshuaggarwal3947 3 ปีที่แล้ว

    Really awesome👏👏👏😊

  • @johnventrella5753
    @johnventrella5753 2 ปีที่แล้ว

    Thank you so much! How would you display though an image from an aws storage and not the media/static folder?

  • @yousifahmed257
    @yousifahmed257 ปีที่แล้ว

    Very very 😍awesome

  • @schoolive7977
    @schoolive7977 4 ปีที่แล้ว +1

    Thank u... But how to save that in project directory

  • @schoolive7977
    @schoolive7977 4 ปีที่แล้ว +1

    Thank u.. but how to save that in project directory

  • @bio10tv83
    @bio10tv83 7 ปีที่แล้ว

    That's too awesome, thank you so much !

  • @scottnorman2485
    @scottnorman2485 2 ปีที่แล้ว

    Awesome video! Any suggestions on template design for using render_to_pdf to create a pdf containing a bar chart? Have tried your method using external style sheets and chart will not render.

    • @charlesu49
      @charlesu49 ปีที่แล้ว

      did you find a solution for this?

  • @palisthaprajapati1767
    @palisthaprajapati1767 5 ปีที่แล้ว +2

    My template contains nepali words. So while I generate pdf, it returns UnicodeEncodeError at /application-view/92/pdf/ 'latin-1' codec can't encode characters in position 1058-1062: ordinal not in range(256) error. How can I solve it?

    • @what-the-code
      @what-the-code 2 ปีที่แล้ว

      Have u got solution? Plz share

  • @kerolosemad1
    @kerolosemad1 4 ปีที่แล้ว

    amazing as usual

  • @luisvelasco400
    @luisvelasco400 3 ปีที่แล้ว

    Is there a way to make the Template and context dynamic? So you can put the button in others templates, and create the PDF based in the actual template?

  • @mdrashadalhasanrony8694
    @mdrashadalhasanrony8694 7 ปีที่แล้ว +1

    Great Tuturial. Really helpful :-)

  • @haijuntang9568
    @haijuntang9568 7 ปีที่แล้ว +1

    if i change the data in js file when loading html, or draw a picture on loading or so on, i think this method is invalid. what can i do? Thanks. sorry for my poor English.

  • @marvinmuu7940
    @marvinmuu7940 7 ปีที่แล้ว

    What is your opinion about Weasyprint? It seems the more common package for me, but we are experienceing some problems.. Did you use it before and whats your favourite?

  • @kriteshag003
    @kriteshag003 7 ปีที่แล้ว +1

    How can we e-mail the generated pdf? Btw., this tutorial is awesome! Thank you very much.

    • @CodingEntrepreneurs
      @CodingEntrepreneurs  7 ปีที่แล้ว +4

      +Kritesh Agarwal ahh good question!
      You have to save it locally (on your server) and then add it as an attachment to your email. Django docs show you how to add attachments.
      Does that help? 😬

    • @kriteshag003
      @kriteshag003 7 ปีที่แล้ว +1

      Hey Justin, yeah it helps! Now, I get the idea. (Sorry, for replying late!)
      I really want to thank you, because now I am doing the projects I always dreamed of because of your knowledge and videos on django. I learned django completely from you. You're awesome. My 'engineer-friends' are now referring your tutorials to their colleagues to improve their django skills as I code like a boss. :-)
      Btw, I am facing difficulties in understanding how to manage files on django. I want to upload multiple pictures taken from a webcam and upload it, and other kind of similar stuff like managing pdf documents and stuff belonging to a particular user. I want to do these using apis and not through django forms.
      Where should I go to learn about the management of files on django and web? Should I refer django docs or any of your tutorials or any other place? The 'Managing Files' in django docs, is going slightly over my head.
      Thanks, really, you're awesome.

    • @mohitgoyal3494
      @mohitgoyal3494 5 ปีที่แล้ว

      @@CodingEntrepreneurs but for email we need to have a file name. But here we dont have any file name which is rendered to pdf. Plz suggest how could i save it locally

  • @dubey_ji
    @dubey_ji 4 ปีที่แล้ว

    thank you so much !!!!!!!!!!!!!!!!!!

  • @Bilal5619
    @Bilal5619 5 ปีที่แล้ว +1

    Nice work..

  • @i_youtube_
    @i_youtube_ 7 ปีที่แล้ว +4

    Great tutorial

  • @bouhannacheabdallah
    @bouhannacheabdallah 3 ปีที่แล้ว

    Does stylesheet method changed or just still the inline way only?

  • @germantellez2710
    @germantellez2710 4 ปีที่แล้ว

    you're my hero

  • @neuzhong
    @neuzhong 5 ปีที่แล้ว

    Good introduction, please slow down don't switch screen too often.

  • @sheddtutt7875
    @sheddtutt7875 2 ปีที่แล้ว

    how can I enable auto download/or a normal download if I am using React Js in the client side?
    I need help on that

  • @ГригорийГришин-х4щ
    @ГригорийГришин-х4щ 7 ปีที่แล้ว +6

    What about UTF-8????

    • @jollygoal
      @jollygoal 5 ปีที่แล้ว +2

      In utils.py you should change
      pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
      to
      pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result)

    • @tizyanoonie8483
      @tizyanoonie8483 3 ปีที่แล้ว

      @@jollygoal I tried this, does not work

  • @renoriandito3333
    @renoriandito3333 4 ปีที่แล้ว

    It works the first time I use it. Great tutorial !
    3 issues I need assistance please :
    1. Data from Django TextField type does not rendered as multi-line, but as single line.
    2. Foot : pagecount error. It shows twice. eg. 4 pages, showed as 44
    3. Managed to show it as pdf on the browser, but error after download : there's symbol : ' before and after the file name. eg. 'report.pdf'. Also when I open it with Adobe, it shows blank page.
    Help please.

  • @robelmorka5522
    @robelmorka5522 3 ปีที่แล้ว

    In my geonode, it says "ImportEroor: No module named xhtml2pdf". how to fix it? i downloaded it, but it still erroe

  • @iqbalmuhammad5297
    @iqbalmuhammad5297 5 ปีที่แล้ว

    Nice tutorial. I just learned django your tutorial been big help. BTW I wondering is it possible to produce idcard with this xhtm2pdf.

    • @kaustavsengupta8757
      @kaustavsengupta8757 5 ปีที่แล้ว

      Well actually it is possible sort of, if you want to produce idcard for office or school. I will suggest you to learn more about styling and css, where you can easily be able to render idcard and style the design of it. Anyway if using for commercial purposes, it is best to first make a PDF and then convert the PDF file into Coral Draw format. Hope this helped you

  • @mozenrathzerksis174
    @mozenrathzerksis174 ปีที่แล้ว

    how should i bring dynamic data into context from search query template

  • @nabinlama146
    @nabinlama146 4 ปีที่แล้ว

    thank you, brother. But could you tell me that in place of context, how to insert data from database?

    • @CodingEntrepreneurs
      @CodingEntrepreneurs  4 ปีที่แล้ว

      Do you know Django? It’s just a queryset that you can unpack

  • @martincastellon5701
    @martincastellon5701 4 ปีที่แล้ว

    Do you think that JSPDF a better option now?

  • @mohammadfaiqkashifi3618
    @mohammadfaiqkashifi3618 6 ปีที่แล้ว +1

    hi dear!
    my question is that when I send the template that has the Persian language. the pdf will create but instead, my Persian data is then shown in hashed data like the square square
    how can fix it .?

    • @kaustavsengupta8757
      @kaustavsengupta8757 5 ปีที่แล้ว

      I know it's kinda late but you might want to look upon UTF -8 encoding

    • @what-the-code
      @what-the-code 2 ปีที่แล้ว

      Have u got solution? Plz share

  • @leofernandez6087
    @leofernandez6087 4 ปีที่แล้ว

    no soporta bootstrap 4, alguna ayuda? Intente agregandolo con la etiqueta style, pero no soporta algunas funciones de css.

  • @neofit3157
    @neofit3157 7 ปีที่แล้ว

    very cool, nice!

  • @misaelbarreto
    @misaelbarreto 7 ปีที่แล้ว

    Simple and very useful tutorial. Thanks so much!

  • @oshafoster9390
    @oshafoster9390 4 ปีที่แล้ว

    I am trying to use bootstrap to style the PDF, the bootstrap styles show up in the html but not the pdf. The link to bootstrap is in the head comp. I read one note the author thought it should work, has anyone figured it out?

  • @aishchandak2887
    @aishchandak2887 6 ปีที่แล้ว +2

    in views.py how can i take data directly from the form i have in my django project? like, "session_id": ??

    • @kerolosemad1
      @kerolosemad1 4 ปีที่แล้ว

      take data from a form and passed it like passing context to template.render

  • @Rochanism
    @Rochanism 7 ปีที่แล้ว

    thanks for such a good lecture. will be making changes as per my need.
    for:
    ImportError: cannot import name inputstream
    pip install html5lib==1.0b8

  • @golgottera8205
    @golgottera8205 6 ปีที่แล้ว

    Thanks man!!

  • @ericxls93
    @ericxls93 3 ปีที่แล้ว

    inline css only... my template is full of bootstrap. mmm. Suggestions?

  • @colzlife1231
    @colzlife1231 4 ปีที่แล้ว

    Not Running in a format and file can't be opened after it gets download

  • @Bujjiandmeonly
    @Bujjiandmeonly 6 ปีที่แล้ว

    Nice tutorial.
    How do i convert/export PDF into HTML? I have more than 20K PDF files.. please suggest

    • @kaustavsengupta8757
      @kaustavsengupta8757 5 ปีที่แล้ว

      There is actually a simple hack that I learnt from stackoverflow. Best is to use python module name pandas. Upload those all files onto pandas, convert them into Excel and then import it in your database. Mind it that you will need some database fixture too...

  • @shoibansari5676
    @shoibansari5676 5 ปีที่แล้ว

    It's really nice but it doesn't work on other screen sizes like tablet and cell phones...

  • @krebill
    @krebill ปีที่แล้ว

    Thank's

  • @syedmudaseer4709
    @syedmudaseer4709 5 ปีที่แล้ว

    How can I use session in html template, and I am using external CSS but it is not giving any effect

  • @alekinyua2791
    @alekinyua2791 5 ปีที่แล้ว

    Thanks for the video but my pdf just downloaded once its the same for all users and stopped am using idm .

  •  3 ปีที่แล้ว

    What about direct printing?

  • @mohammedlamaallaoui2464
    @mohammedlamaallaoui2464 5 ปีที่แล้ว

    I have à project developed with zope , and i want to immgrate this project in django ? how to convert zope to django ?

  • @rishinandwani1424
    @rishinandwani1424 6 ปีที่แล้ว

    very helpful guide

  • @hendryandreanata6955
    @hendryandreanata6955 5 ปีที่แล้ว +1

    i cant get my image , please help me. appear error " Need a valid file name! "

    • @asisbagga3838
      @asisbagga3838 4 ปีที่แล้ว

      Same here man, i am not able to get it too

    • @rutujamurge7713
      @rutujamurge7713 3 ปีที่แล้ว

      did u get your images after solving this

  • @absolutedgefindout726
    @absolutedgefindout726 6 ปีที่แล้ว

    How would we use a queryset to render the PDF?

  • @naziburrahman852
    @naziburrahman852 6 ปีที่แล้ว

    Requesting a tutorial on the problem bellow:
    1. A web app that requires login to user it and a logout feature to come out
    2. after login user can input : name,age,salary
    3. the interface should be in bootstrap
    4. report button will generate a report in pdf (report contains every persons name and age and salary serially )
    5. it should be secured enough to deploy and
    6. Finally deployment process
    please it will clear my concept
    help me......

    • @srikanthtumpudi536
      @srikanthtumpudi536 6 ปีที่แล้ว

      bro plz contact me my whatsapp no:9985385327 explain this i will do it for you

  • @vvHax
    @vvHax 6 ปีที่แล้ว

    Great vid

  • @jeanpierrer.6512
    @jeanpierrer.6512 6 ปีที่แล้ว

    minute 7:17 error : 'dict' object has no attribute 'render_context'
    help me please ?

  • @ab-rx1gh
    @ab-rx1gh 7 ปีที่แล้ว +1

    awesome dude

  • @basavarajus2061
    @basavarajus2061 4 ปีที่แล้ว

    I have a csv file which contains invoice details of multiple customers, and I have an HTML template. I want to automatically generate invoices in pdf format using django and python. Can someone please point me to related videos and articles?

  • @mohdzaidkhan4676
    @mohdzaidkhan4676 2 ปีที่แล้ว

    how can we render Js + html into pdf using python ??

  • @jazzeverything121
    @jazzeverything121 5 ปีที่แล้ว

    hi justin have you try to use a django-wkhtmltopdf ? in ubuntu server

  • @bhuwanbhaskar5381
    @bhuwanbhaskar5381 4 ปีที่แล้ว

    Using render to pdf i can't convert image also in pdf , how to change image also

  • @adithyadinesh1996
    @adithyadinesh1996 7 ปีที่แล้ว

    Why cant i use bootstrap in invoice.html anyway to use it plz help!

  • @avkaransingh374
    @avkaransingh374 6 ปีที่แล้ว

    i want to open only pdf file with django how to do?

  • @narongthatthanyawet973
    @narongthatthanyawet973 4 ปีที่แล้ว

    I cannot do it, it returns the blank page

  • @palanikumar8023
    @palanikumar8023 4 ปีที่แล้ว

    what is local.py...is that settings.py??

  • @Name-pn5rf
    @Name-pn5rf 4 ปีที่แล้ว

    how to get data from database into pdf?

  • @infaumedutech4263
    @infaumedutech4263 5 ปีที่แล้ว

    how can i save that "generated pdf file" to a django model without showing the pdf file

  • @stej2248
    @stej2248 4 ปีที่แล้ว

    I need your help. How can I contact you?

  • @yajantbhawsar2481
    @yajantbhawsar2481 2 ปีที่แล้ว

    Can anyone help with this:
    latin-1' codec can't encode character '\u2713' in position 8235: ordinal not in range(256)
    from:
    pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)

    • @what-the-code
      @what-the-code 2 ปีที่แล้ว

      Have u got solution? Plz share

  • @adithyadinesh1996
    @adithyadinesh1996 7 ปีที่แล้ว

    how to make tat pdf download in browser ?
    on click of a button

    • @jeril983
      @jeril983 7 ปีที่แล้ว

      add an 'a' tag with the href="{% url foobar %}?download=true" or href={% url foobar download=true %} if you have regex in urls.py

  • @mirnagama2281
    @mirnagama2281 5 ปีที่แล้ว

    It didn't work for me...
    This happened: 'django.template.exceptions.TemplateDoesNotExist: pdf/invoice.html'

    • @jazzeverything121
      @jazzeverything121 5 ปีที่แล้ว

      make sure you input correct path for invoice.html

  • @abdillahmohamed9585
    @abdillahmohamed9585 5 ปีที่แล้ว

    like it

  • @mahmoudfathy6963
    @mahmoudfathy6963 4 ปีที่แล้ว

    how to define arabic lang ??

  • @lucasoliveira4641
    @lucasoliveira4641 7 ปีที่แล้ว

    How add watermark (image)?

    • @CodingEntrepreneurs
      @CodingEntrepreneurs  7 ปีที่แล้ว

      +Lucas Oliveira great question. I’m assuming you mean through python? You can probably use PIL to accomplish this (aka pillow)

  • @AhmedTheCoder
    @AhmedTheCoder 4 ปีที่แล้ว

    Arabic fonts not working