【问题标题】:Appengine - Reportlab PDFAppengine - Reportlab PDF
【发布时间】:2011-04-06 23:12:39
【问题描述】:

我正在使用 Google appengine 并希望使用 reportlab 生成 PDF。 该应用程序运行良好,可以生成像“Hello World”这样的 PDF 文件。 但我想要的是使用用户输入的数据从表单中获取数据并动态生成 PDF。

任何人都可以分享一段代码吗?我将不胜感激。

【问题讨论】:

  • 您有具体问题吗? ReportLab 文档有很多示例,但并非特定于 App Engine。

标签: python google-app-engine reportlab


【解决方案1】:

我假设你使用 webapp 框架。

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.out.write("""
          <html>
            <body>
              <form action="/makepdf" method="post">
                <div><textarea name="content" rows="3" cols="60"></textarea></div>
                <div><input type="submit" value="Make a PDF for me"></div>
              </form>
            </body>
          </html>""")


class MakePDF(webapp.RequestHandler):
    def post(self):
        # now here you can make your PDF like you did for the "Hello world" one
        # and you can access the entered data like this: self.request.get('content')

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/makepdf', MakePDF)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

【讨论】:

  • 也许,我解释得不好。用户输入数据,数据显示在表格或 div 的另一个页面上。不是形式。如何获取数据并转换为 PDF。我试过做teacher.name,但它给出了错误。
  • 用户用教师类的属性填写表格。然后您将被重定向到另一个页面,其中显示可以编辑、删除或打印为 PDF 的数据。这就是问题所在。如何用他输入的数据生成PDF?可能必须访问模型,对。因为数据是动态的,您可以输入其他值,PDF 必须显示实际数据。有人可以帮忙吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-17
  • 1970-01-01
  • 2020-01-28
  • 2013-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多