获取您的 Django 服务器
all_members.html
details.html
views.py
urls.py
 
<!DOCTYPE html>
<html>
<head>
  <title>The Members</title>
</head>
<body>

<h1>Members</h1>
  
<ul>
  {% for x in mymembers %}
    <li><a href="details/{{ x.id }}">{{ x.firstname }} {{ x.lastname }}</a></li>
  {% endfor %}
</ul>

</body>
</html>                  
<!DOCTYPE html>
<html>
<head>
  <title>{{ mymember.firstname }} {{ mymember.lastname }}</title>
</head>
<body>

<h1>{{ mymember.firstname }} {{ mymember.lastname }}</h1>
  
<p>Phone: {{ mymember.phone }}</p>
<p>Member since: {{ mymember.joined_date }}</p>

<hr>

<p>Back to <a href="/members">Members</a></p>

</body>
</html>                  
from django.http import HttpResponse
from django.template import loader
from .models import Member

def members(request):
  mymembers = Member.objects.all().values()
  template = loader.get_template('all_members.html')
  context = {
    'mymembers': mymembers,
  }
  return HttpResponse(template.render(context, request))
  
def details(request, id):
  mymember = Member.objects.get(id=id)
  template = loader.get_template('details.html')
  context = {
    'mymember': mymember,
  }
  return HttpResponse(template.render(context, request))                  
from django.urls import path
from . import views

urlpatterns = [
    path('members/', views.members, name='members'),
    path('details/<int:id>', views.details, name='details'),
]                  
127.0.0.1:8000/members/details/1