对于我的项目,我试图生成一个 csv 文件以在 dygraphs 中读取。 Dygraphs 是一个绘制 csv 文件的 Javascript 库。 在 Dygraphs 的文档中,它说当您指定一个文件时,它会发送一个 XHR 来获取 csv。因此,在我看来,我将其解释为我需要一个
if request.is_ajax():
但这真的是这个意思吗?
我的问题是我的打印图不会显示在页面上。 我从 Firebug 收到的错误消息是:
"NetworkError: 404 Not Found - http://www.albedo.csrcdev.com/VAM/Appearance/VAMStyleSheet.css
"NetworkError: 404 Not Found - http://www.albedo.csrcdev.com/VAM/3_0_3/VAM.js/
ReferenceError: VAM_ValSumFmtBullet is not defined
ReferenceError: VAM_GetById is not defined
我真的不知道那告诉我什么,但是当我有一个静态 csv 文件时,图表确实显示了,所以我很确定它只是没有抓取动态创建的 csv 文件。
感谢任何帮助。
谢谢
# The function does work, when I type the url manually, it prompts me
# to download the csv and is all correct.
def dygraphs_generate_csv( request, year=None ):
if request is_ajax():
if year is None:
year = datetime.today().year
entries = DataEntry.objects.all().filter(observation_Date__year=year)
return render( request, 'pages/output.csv',
{'entries': entries},
content_type='text/csv'
)
请您参考如下方法:
这些错误与您的 CSV 生成无关。如果您的 JS/CSS 没有 404,您的页面可能会呈现得更正确。
如果 CSV 是一个挑战,您还可以将原生 JavaScript 数组传递给 dygraphs。参见 http://dygraphs.com/data.html了解更多信息。
