我试图让 django 模型对象显示在 html 页面上。当然,当我尝试使用 {{ object }} 时,我得到了一个错误。
如何正确获取 django 数据模型并使用 javascript 操作属性?
网址:
('^all_companies$', 'companies.views.all_companies')
风景:
def all_companies(request):
companies = Company.objects.all().order_by('id')[:5];
return direct_to_template(request, 'all_companies.html', {'companies': companies} );
的HTML:
{% block sidebar %}
<div id="sidebar">
<!-- like google maps, short list of company info -->
<ul>
{% for comp in companies %}
<li>{{ comp }}</li>
{% endfor %}
</ul>
</div>
{% endblock %}
js:
var tmp = {{ companies }}