Django loading mysql data into template correctly

Posted by user805981 on Stack Overflow See other posts from Stack Overflow or by user805981
Published on 2012-10-19T21:41:43Z Indexed on 2012/10/19 23:01 UTC
Read the original article Hit count: 385

I'm new to django and I'm trying to get display a list of buildings and sort them alphabetically, then load it into an html document. Is there something that I am not doing correctly?

below is models.py

class Class(models.Model):
    building = models.CharField(max_length=20)
    class Meta:
        db_table = u'class'
    def __unicode__(self):
        return self.building

below is views.py

views.py

def index(request):
    buildinglist = Class.objects.all().order_by('building')
    c = {'buildinglist': buildinglist}
    t = loader.get_template('index.html')
    return HttpResponse(t.render(c))

below is index.html

index.html

{% block content%}
<h3>Buildings:</h3>
<ul>
    {% for building in buildinglist %}
        <li>
            <a href='www.{% building %}.com'>
                            # ex. www.searstower.com
        </li>
    {% endfor %}
</ul>
{% endblock %}

Can you guys point me in the right direction? Thank you in advance guys! I appreciate your help very much.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models