Adding a Template to the Application
To add some HTML around the qualities, we will make a template for the application.
All template should be situated in the templates folder off your application, in the event that you have not previously made a templates folder, do it now.
In the templates folder, make a record named index.html, with the accompanying substance:
members/templates/index.html:
Did you notice the {% %} and {{ }} parts? They are called template tags.<h1>Members</h1>
<table border="1">
{% for x in mymembers %}
<tr>
<td>{{ x.id }}</td>
<td>{{ x.firstname }}</td>
<td>{{ x.lastname }}</td>
</tr>
{% endfor %}
</table>
Modify the View
Change the indexindex view to include the template:
members/views.py:
from django.http import HttpResponse
from django.template import loader
from .models import Members
def index(request>
:
mymembers = Members.objects.all(>
.values(>
template = loader.get_template('index.html'>
context = {
'mymembers': mymembers,
}
return HttpResponse(template.render(context, request>
>
The record view does the accompanying:
In the browser window, type 127.0.0.1:8000/members/in the address bar.