小编Dr *_*use的帖子

使用Django和Reportlab从HTML生成PDF

我带着一个我无法回答的新问题回来,整整一天都摸不着头脑.

我想通过点击"下载PDF"按钮从网页生成PDF.我尝试了几个模块,包括Reportlab和XHTML2PDF,但我无法生成任何pdf,也无法下载...这是我在Reportlab中做的,在Django网站中将HTML渲染为PDF

- - views.py - -

import cStringIO as StringIO
import ho.pisa as pisa
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
from cgi import escape

def index_data(request):
#Code to generate data
     return render(request, "analytics/stat.html", locals())
     return render_to_pdf(
        'analytics/stat.html',
        {
            'pagesize':'A4',
            'mylist': results,
        }
    )

def render_to_pdf(template_src, context_dict):
    template = get_template(template_src)
    context = Context(context_dict)
    html  = template.render(context)
    result = StringIO.StringIO()

    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        return HttpResponse(result.getvalue(), content_type='application/pdf')
    return HttpResponse('We …
Run Code Online (Sandbox Code Playgroud)

python pdf django reportlab

6
推荐指数
1
解决办法
1万
查看次数

使用Eonasdan datetimepicker时,无法选择minDate和maxDate在同一天的日期和时间

使用bootstrap-datetimepicker v.4.17.47 时,我有一个奇怪的行为.这是我的选择器配置:

format: 'YYYY-MM-DD HH:mm',
showTodayButton: true,
useCurrent: false,
showClear: true,
minDate: moment('{{ ts_beg }}'),
maxDate: moment('{{ ts_end }}')
Run Code Online (Sandbox Code Playgroud)

当设置的minDate和的maxDate的同一天,但不同的时间,比方说2018-2-1 00:002018-2-1 02:00,我无法选择日期和时间: peek 2018-02-05 09-33

有没有人有解决这个问题的解决方法?

javascript eonasdan-datetimepicker

6
推荐指数
1
解决办法
321
查看次数

应用不适用于使用 Apache Beam 的 ParDo 和 DoFn

我正在实施 Pub/Sub 到 BigQuery 管道。它看起来类似于How to create read transform using ParDo and DoFn in Apache Beam,但在这里,我已经创建了一个 PCollection。

我正在遵循Apache Beam 文档中描述的内容来实现 ParDo 操作以使用以下管道准备表行:

static class convertToTableRowFn extends DoFn<PubsubMessage, TableRow> {
    @ProcessElement
    public void processElement(ProcessContext c) {
        PubsubMessage message = c.element();
        // Retrieve data from message
        String rawData = message.getData();
        Instant timestamp = new Instant(new Date());
        // Prepare TableRow
        TableRow row = new TableRow().set("message", rawData).set("ts_reception", timestamp);
        c.output(row);
    }
}

// Read input from Pub/Sub
pipeline.apply("Read from …
Run Code Online (Sandbox Code Playgroud)

google-cloud-dataflow apache-beam

1
推荐指数
1
解决办法
2255
查看次数