148
rated 0 times
[
152]
[
4]
/ answers: 1 / hits: 16941
/ 12 Years ago, fri, april 27, 2012, 12:00:00
I am trying to get the django model object to show on a html page. Of course when I tried to use {{ object }}, I get an error.
How do I properly get the django data model and manipulate the attributes using javascript?
the url:
('^all_companies$', 'companies.views.all_companies')
the view:
def all_companies(request):
companies = Company.objects.all().order_by('id')[:5];
return direct_to_template(request, 'all_companies.html', {'companies': companies} );
the 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 %}
the js:
var tmp = {{ companies }}
More From » python