我正在使用 Google appengine 并希望使用 reportlab 生成 PDF。该应用程序运行良好,可以生成诸如“Hello World”之类的 PDF 文件。但我想要的是使用用户输入的数据从表单中获取数据并动态生成 PDF。
任何人都可以分享一段代码吗?我将感激不尽。
我正在使用 Google appengine 并希望使用 reportlab 生成 PDF。该应用程序运行良好,可以生成诸如“Hello World”之类的 PDF 文件。但我想要的是使用用户输入的数据从表单中获取数据并动态生成 PDF。
任何人都可以分享一段代码吗?我将感激不尽。
我假设您使用 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()