areke
areke

Reputation: 1093

How do I let Google App Engine have a download link that downloads something from a database?

Okay, let's say I have a database

Class Content(db.Model):
    code=db.TextProperty()

And I wanted to supply a download link on the webpage that would download the content of code. How would I do this?

I am using python and jinja2

Upvotes: 1

Views: 316

Answers (1)

David Wolever
David Wolever

Reputation: 154682

You'd create a view that sends back the content of code (assuming that you're using the "webapp" framework):

class MainPage(webapp.RequestHandler):
    def get(self):
        content = Content.get(…)
        self.response.headers['Content-Type'] = 'application/octet-stream'
        self.response.out.write(content.code)

Note that you might want to set the Content-Type to something more specific. Also, if you want to force the browser to download the file (instead of possibly displaying the file), you can set the Content-Disposition header: headers['Content-Disposition'] = 'attachment; filename=some_filename.txt'.

Upvotes: 6

Related Questions