TECH I.S. テックアイエスガイド エディター
template.html
views.py
<!DOCTYPE html> <html> <body> <table border='1'> <tr> <th>ID</th> <th>Firstname</th> <th>Lastname</th> </tr> {% for x in mymembers %} <tr> <td>{{ x.id }}</td> <td>{{ x.firstname }}</td> <td>{{ x.lastname }}</td> </tr> {% endfor %} </table> <p>In views.py you can see how to import and fetch members from the database.</p> </body> </html>
from django.http import HttpResponse from django.template import loader from .models import Member def testing(request): mydata = Member.objects.all() template = loader.get_template('template.html') context = { 'mymembers': mydata, } return HttpResponse(template.render(context, request))
127.0.0.1:8000/testing
Try It | Online Web Tutorials