我正在尝试将csv文件作为附件下载流式传输.CSV文件大小为4MB或更多,我需要一种方法让用户主动下载文件,而无需等待创建所有数据并首先提交到内存.
我首先使用自己的基于Django FileWrapper
类的文件包装器.那失败了.然后我在这里看到了一个使用生成器来传输响应的方法:
如何使用Django流式传输HttpResponse
当我在生成器中引发错误时,我可以看到我正在使用该get_row_data()
函数创建正确的数据,但是当我尝试返回响应时它返回空.我也禁用了Django GZipMiddleware
.有谁知道我做错了什么?
编辑:我遇到的问题是ConditionalGetMiddleware
.我不得不更换它,代码在下面的答案中.
这是观点:
from django.views.decorators.http import condition
@condition(etag_func=None)
def csv_view(request, app_label, model_name):
""" Based on the filters in the query, return a csv file for the given model """
#Get the model
model = models.get_model(app_label, model_name)
#if there are filters in the query
if request.method == 'GET':
#if the query is not empty
if request.META['QUERY_STRING'] != None:
keyword_arg_dict = {}
for key, value in request.GET.items():
#get the query filters …
Run Code Online (Sandbox Code Playgroud) 我创建了一个眼镜蛇命令并添加了一个标志:
cmd.Flags().StringVarP(&primaryIP, "primary-ip", "p", "", "Help text")
Run Code Online (Sandbox Code Playgroud)
除了自己检查值并返回错误之外,有没有办法让它成为必需的?
无论如何,PIL会调整到我给它的确切尺寸吗?或者,如果我给它类似的Image.ANTIALIAS
论点,它会尝试保持纵横比吗?
我正在运行一个go app,它正在创建prometheus指标,这些指标是特定于节点的指标,我希望能够将节点IP添加为标签.
有没有办法从Pod中捕获节点IP?
我有一个奇怪的问题.当我从这个类中调用"UserShowStatsSuggestions"时:
var UserShowStatsPanelBody = React.createClass({
getInitialState: function() {
return {data: []};
},
componentDidMount: function() {
// Get the show
var showUrl = "/api/v1/show/" + this.props.showStats.show + "/";
$.ajax({
url: showUrl,
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
render: function() {
var statElements = [];
// Create the user show stats
if (this.props.showStats) {
var showID = this.state.data.id;
var showLink = "/leaderboards/show/" + showID + "/";
var recapLink = …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个测试来断言函数因无效输入而发生恐慌,但 Ginkgo 将恐慌记录为失败,而不是按预期传递结果。
\nfunc ParseUnixTimeString(unixTimeString string) time.Time {\n i, err := strconv.ParseInt(unixTimeString, 10, 64)\n if err != nil {\n panic(fmt.Sprintf("could not parse time: %s", err.Error()))\n }\n return time.Unix(i, 0)\n}\n\nfunc TestFormat(t *testing.T) {\n gomega.RegisterFailHandler(ginkgo.Fail)\n ginkgo.RunSpecs(t, "Format Suite")\n}\n\nvar _ = ginkgo.Describe("Format Tests", func() {\n ginkgo.Describe("When formatting the date", func() {\n ginkgo.It("should panic if the time can't be formatted", func() {\n gomega.Expect(\n tools.ParseUnixTimeString("2314321432143124223432434")).To(gomega.Panic())\n })\n})\n
Run Code Online (Sandbox Code Playgroud)\n返回(压缩):
\n\xe2\x80\xa2! [PANICKED] [0.002 seconds]\n[It] should panic if the time can't be formatted\nTest Panicked\ncould not parse …
Run Code Online (Sandbox Code Playgroud) go ×2
python ×2
csv ×1
django ×1
ginkgo ×1
gomega ×1
javascript ×1
kubernetes ×1
reactjs ×1
resize ×1
streaming ×1
testing ×1
unit-testing ×1