简体   繁体   English

如何在Django应用程序中使用运行在docker-compose的wkHTMLtoPDF

[英]How to use wkHTMLtoPDF running in docker-compose in Django application

I have a problem with undestanding on how to use wkHTMltoPDF, that I run in docker-compose and Django. Also I can't understand how to setup it in Django and use it in the right way.我对如何使用 wkHTMLtoPDF 有疑问,我在 docker-compose 和 Django 中运行。我也不明白如何在 Django 中设置它并以正确的方式使用它。 I will be very glad for any help.如果有任何帮助,我将非常高兴。 My docker-compose.yml:我的 docker-compose.yml:

version: '3.7'

services:
  db:
    image: postgres:13.0
    restart: always
    environment:
      POSTGRES_PASSWORD: trytofindme
    ports:
      - 15432:5432
  adminer:
    image: adminer
    restart: always
    ports:
      - 8020:8080
  wkhtmltopdf:
    image: openlabs/docker-wkhtmltopdf-aas:latest
    volumes:
      - .:/data

So, I can't even imagine where I should do it in Django. The example of usage that I need: on main page I fill some forms and then click button "Generate".所以,我什至无法想象在 Django 中我应该在哪里做。我需要的用法示例:在主页上我填写一些 forms,然后单击“生成”按钮。 It should send async requests on generating pdf file of this page with filled forms. Can anybody help me to realise it?它应该在生成此页面的 pdf 文件时发送异步请求,其中填充了 forms。有人可以帮助我实现它吗?

You need to setup a new image, you can take use python 3.7 as base image.您需要设置一个新镜像,您可以使用 python 3.7 作为基础镜像。 The wkhtmltopdf binaries can be made usinghttps://github.com/aantonw/docker-alpine-wkhtmltopdf-patched-qt .可以使用https://github.com/aantonw/docker-alpine-wkhtmltopdf-patched-qt制作 wkhtmltopdf 二进制文件。

This is how my docker file looked.这就是我的 docker 文件的样子。

FROM python:3.7-alpine

COPY ./requirements.txt .

RUN set -e; \
        apk add --no-cache mariadb-connector-c-dev ;\
        apk add --no-cache --virtual .build-deps \
        gcc \
        libc-dev \
        linux-headers \
        mariadb-dev \
        jpeg-dev \
        zlib-dev \
        libffi-dev \
        musl-dev \
        libxml2-dev \
        libxslt-dev \
        wkhtmltopdf \
        poppler-utils;
COPY docker_files/wkhtmltopdf /usr/bin/wkhtmltopdf
COPY docker_files/wkhtmltoimage /usr/bin/wkhtmltoimage
RUN set -e; \
    pip install --upgrade pip; \
    pip install -r requirements.txt;
COPY ./src /app
WORKDIR /app
CMD [ "python", "manage.py", "runserver" ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM