Skip to content

Instantly share code, notes, and snippets.

@krisys
Created January 27, 2012 03:36
Show Gist options
  • Save krisys/1686842 to your computer and use it in GitHub Desktop.
Save krisys/1686842 to your computer and use it in GitHub Desktop.
MVC in Django
# models.py
class Person(models.Model):
firstname = models.CharField(max_length=30)
lastname = models.CharField(max_length=30)
# views.py
def list_view(request):
person_list = Person.objects.all()
return HttpResponse('template.html', {'persons': person_list} )
# template.html
'''
<html>
<table>
<tr><th>First Name</th><th>Last Name</th>
{% for person in persons %}
<tr><td>{{person.firstname}} </td><td> {{person.lastname}}</td></tr>
{% endfor %}
</table>
</html>
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment