没有从django中的视图到模板获取json数据

时间:2016-02-05 05:27:22

标签: json django-templates django-views

我想从视图和crate柱形图中获取json数据。下面是代码 views.py

url(r'^percent/$', TemplateView.as_view(template_name='PFTpercentchange.html'), name='PFTpercentChange')

urls.py

var data=$.getJSON('{% url "PFTpercentchange" %}');

PFTpercentchange.html

`Dim ws As Worksheet
Set ws = ActiveSheet

With ws

'find last row of data in column A
Dim lRow As Long
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
Dim rngStart As Range
Set rngStart = .Range("A3")

'set counter variable for naming tables
Dim i As Long
i = i + 1
Dim oneDown As Long
Set oneDown =rngStart.Offset(1)

Do

if Len(oneDown) > 0 Then
    'create table range
    Set rngTable = .Range(rngStart.End(xlToRight),rngStart.End(xlDown))
    'create table
    .ListObjects.Add(xlSrcRange, rngTable.Resize(rngTable.Rows.Count, rngStart.End(xlToRight).Column), , xlYes).Name = "Table" & i
    'set style
    .ListObjects("Table" & i).TableStyle = "TableStyleLight9"
    'find next table range start
    Set rngStart = rngTable.End(xlDown).Offset(2)
 Else
'create table range
    Set rngTable = .Range(rngStart.End(xlToRight))
    'create table
    .ListObjects.Add(xlSrcRange, rngTable.Resize(rngTable.Rows.Count, rngStart.End(xlToRight).Column), , xlYes).Name = "Table" & i
    .ListObjects("Table" & i).TableStyle = "TableStyleLight9"
    Set rngStart = rngTable.End(xlDown).Offset(2)

End If
    i = i + 1

Loop Until rngStart.Row > lRow

End With`

我得到错误没有反向匹配。怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

为什么你在url中写了TemplateView?要调用PFTpercentChange函数,你可以像这样制作网址,

url(r'^percent/$',PFTpercentChange.as_view(), name='PFTpercentChange').