|
| 1 | +from django.http import HttpResponse |
1 | 2 | from django.shortcuts import render |
| 3 | +from django.template import loader |
| 4 | +from django.views.generic.list import ListView |
2 | 5 |
|
3 | | -# Create your views here. |
| 6 | +from community_db.models import Person |
| 7 | + |
| 8 | + |
| 9 | +def list_persons(request): |
| 10 | + html = "<html><body>This is my list of folks<ul>" |
| 11 | + |
| 12 | + for person in Person.objects.all(): |
| 13 | + html += f"<li>{person.first_name} {person.last_name} from {person.country}</li>" |
| 14 | + |
| 15 | + html += "</ul></body></html>" |
| 16 | + return HttpResponse(html) |
| 17 | + |
| 18 | + |
| 19 | +# def list_persons_with_template(request): |
| 20 | +# persons = Person.objects.all() |
| 21 | +# template = loader.get_template("community_db/person_list.html") |
| 22 | +# context = {"object_list": persons} |
| 23 | +# return HttpResponse(template.render(context, request)) |
| 24 | + |
| 25 | + |
| 26 | +def list_persons_with_template(request): |
| 27 | + persons = Person.objects.all() |
| 28 | + template = loader.get_template("community_db/person_list_in_base.html") |
| 29 | + context = {"object_list": persons} |
| 30 | + return HttpResponse(template.render(context, request)) |
| 31 | + |
| 32 | + |
| 33 | +# def list_persons_with_template(request): |
| 34 | +# persons = Person.objects.all() |
| 35 | +# context = {"object_list": persons} |
| 36 | +# return render(request, "community_db/person_list.html", context) |
| 37 | + |
| 38 | + |
| 39 | +class PersonListView(ListView): |
| 40 | + model = Person |
| 41 | + template_name = "community_db/person_list_in_base.html" |
0 commit comments