Reputation: 1093
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
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