2

For my project, I am trying to generate a csv-file to be read in dygraphs. Dygraphs is a Javascript library that graphs a csv-file. In the Dygraphs' documentation, it says when you specify a file, it sends an XHR to get the csv. So, in my views, I interpreted that as I need a

if request.is_ajax():

But is that really what it means?

My problem is that my dygraphs won't display on the page. The error message that I'm getting from Firebug is:

"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

I don't really know what that is telling me, but when I had a static csv file, the graph did display so I'm pretty sure it's just not grabbing the dynamically created csv file.

Any help is appreciated.

Thanks


# 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'
            )
4

1 回答 1

1

这些错误与您的 CSV 生成无关。如果您的 JS/CSS 不是 404,您的页面可能会更正确地呈现。

如果 CSV 是一个挑战,您还可以向 dygraphs 传递一个原生 JavaScript 数组。有关详细信息,请参阅http://dygraphs.com/data.html

于 2012-09-06T22:46:33.243 回答