views:

119

answers:

1

Hello, I'm using Google appengine and want to generate a PDF with reportlab. The application works well and can generate PDF's like 'Hello World' and little else. But what I want is to fetch data from a form with the data that the user entered and generate PDF dynamically.

Anyone can share a piece of code? I would be grateful.

+1  A: 

I assume you use the webapp framework.

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()
leoluk
Perhaps, I explained myself badly. The user enters the data and the data are presented on another page in a table or a div. Not in a form.How to get the data and move to PDF. I've tried to do teacher.name and it gives error.
Martin
User fills in a form with the properties of the class Teacher. Then you are redirected to another page where the data are presented that can be edited, deleted or print to PDF. Here's the problem. How to generate the PDF with the data he entered? Probably have to access the Model, right. Because data is dynamic, you can then enter another values and PDF has to show actual data. Could someone help?
Martin