2017-04-13 108 views
1

我在Django中使用chartit,我想将它集成到我的民意调查应用程序。我可以通过输入完整的URL来显示图表,如http://127.0.0.1:8000/polls/chart/。但如果我想访问使用html页面上的按钮,我得到这个NoReverseMatch错误。我必须在这里做什么才能让它工作?Django民意调查:NoReverseMatch与chartit

我url.py有

url(r'^chart/$', views.model_property, name='column_chart'), 

views.py

def model_property(request): 
ballot = Ballot.objects.all()[0] 
ds = DataPool(
     series=[{ 
      'options': { 
       'source': ballot.contestants.all(), 
      }, 
      'terms': [ 
       'contestant_name', 
       'votes' 
      ] 
     }] 
) 

cht = Chart(
     datasource=ds, 
     series_options=[{ 
      'options': { 
       'type': 'column', 
       'stacking': False, 
       'stack': 0, 
      }, 
      'terms': { 
       'contestant_name': [ 
        'votes' 
       ] 
      }}, 
     ], 
     chart_options={ 
      'title': { 
       'text': 'Ballot statistics' 
      }, 
      'xAxis': { 
       'title': { 
        'text': 'Contestants' 
       } 
      } 
     } 
) 
# end_code 
return render_to_response('polls/graph.html', 
          { 
          'chart_list': cht, 
          'title': "Test Chart"}) 

从HTML中我使用的自举按钮,我想访问此链接

<a href="{% url 'polls:chart' %}"> 
     <button type="submit" class="btn btn-primary">{% bootstrap_icon "glyphicon glyphicon-info-sign" %} </button> 
    </a> 

图有看起来像这样

enter image description here

回答

1

使用定位标记中的URL名称空间时出错。

更改:

<a href="{% url 'polls:chart' %}"> 

<a href="{% url 'polls:column_chart' %}"> 
+0

谢谢它的工作原理 –