[英]Unwanted template code attached to response.out.write
I'm stuck with trying to create a downloadable content. 我坚持尝试创建可下载的内容。 I'm using
webapp2.RequestHandler
and I've got the following scenario: 我正在使用
webapp2.RequestHandler
并且出现以下情况:
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'. 现在,尽管第二种情况可以正常工作(如果提供了
SamplePage=2
参数),则文件仅包含单词“ 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; if
块中的self.response.out.clear()
有关,第二个不包含它; self.response.out.clear()
call. self.response.out.clear()
调用。 PS by the way, are you sure you've shown us all the relevant pieces of your code? PS ,顺便说一句,您确定您已经向我们展示了代码的所有相关部分吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.