按照教程(https://github.com/agiliq/django-graphos)和这个stackoverflow post(Displaying graphs using Django-graphos),我无法获取任何要发布到模板中的数据。在
在模型.py在
class MonthlyWeatherByCity(models.Model):
month = models.IntegerField()
boston_temp = models.DecimalField(max_digits=5, decimal_places=1)
houston_temp = models.DecimalField(max_digits=5, decimal_places=1)
class Meta:
verbose_name_plural = "Monthly Weather By Cities"
def __unicode__(self):
return unicode(self.month)
在视图.py在
^{pr2}$在索引.html-图表上没有显示任何内容。在
{% extends 'portal/base.html' %}
{% load static %}
{% block head %}
<!-- Needed for graphos -->
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.categories.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
{% endblock %}
{% block body_block %}
<div class="hero-unit">
<h1>Attack Control Center</h1>
{% if user.is_authenticated %}
<h3>Welcome back {{ user.username }}!</h3>
{% endif %}
</div>
<div class="row-fluid">
<div class="span6">
<h2>Charts</h2>
{{ chart.as_html }}
</div>
</div>
{% endblock %}
一/管理.py贝壳
运行时,将所有内容复制到shell中并-define request=“test”-并运行print graph_test(request)
<div id="ZGScakAPkH" style="width:800px;height:400px;"></div>
<script type="text/javascript">
$(function () {
$.plot(
$("#ZGScakAPkH"),
,
{"series": {"lines": {"show": "true"}}, "legend": {"position": "ne"}, "xaxis": {"mode": "categories"}, "title": "Website"}
);
});
</script>
</div>
已经为{chart.as\u html}}. 我不知道为什么没有导入到我的模板中。在
您不会显示
render_to_response
来自何处。我怀疑功能可能是导致问题的部分原因。在请注意,普通的^{} function is deprecated ,有利于显式处理} function 。在
request
对象的^{还要注意,建议使用class-based views更灵活。在
相关问题 更多 >
编程相关推荐