I'm stuck with trying to create a downloadable content. I'm using webapp2.RequestHandler
and I've got the following scenario:
Here's my class:
class xmlAnalyzer(Handler):
def get(self):
displaySample = self.request.get('SamplePage')
downloadMapping = self.request.get('downloadMapping')
if downloadMapping:
r = self.request.get('srcTgtMapping')
srcTgtMapping = r.split('], [')
csvContents = 'Column name; Source name; Source type; Column name; Target name; Target type;\n'
self.response.headers['Content-Disposition'] = 'attachment; filename=' + str(downloadMapping) +'.csv'
self.response.out.write(csvContents)
elif displaySample == '2':
testString = 'abracadabra'
self.response.headers['Content-Disposition'] = 'attachment; filename=' + 'testFile.csv'
self.response.write(testString)
Now while the second case works fine (if SamplePage=2
parameter is provided) file contains just the word 'abracadabra'. In the first case however, the dowloaded file looks as follows:
Column name; Source name; Source type; Column name; Target name; Target type;
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="/stylesheets/styles.css">
<Content-Type: text/html; charset=utf-8>
<html>
<body class="body">
<div class="main-title">Welcome to XML Analyzer for Informatica PowerCenter</div>
The first line is what I expect. But that should be all. The rest is the template - any idea why is this getting added? Thanks in advance!
Hard to say, but intuitively, deciding by the code you showed us, I would guess it's either...
self.response.out.clear()
in the first if
block—the second one doesn't have it; self.response.out.clear()
call. PS by the way, are you sure you've shown us all the relevant pieces of your code?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.