|

楼主 |
发表于 2018-3-29 09:14:30
|
显示全部楼层
html
<body>
<h1>班级信息列表</h1>
<ul>
<!--python04,python05,python06-->
{%for grade in grades%}
<li>
<a href="{{grade.id}}}"> {{grade.gname}} </a>
</li>
{%endfor%}
</ul>
</body>
views
def gradesStudents(request,num):
grade = Grades.objects.get(pk=num)
studentslist= grade.students_set.all()
return render(request,'myApp/students.html',{'students':studentslist})
app 下的 urls
from django.urls import path
from . import views
urlpatterns = [
path('',views.index),
path('grades/',views.grades),
path('students',views.students),
path('grades/<int:question_id>/',views.gradesStudents),#这一段
根目录下的 url
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myApp.urls')),
path('',include('myApp.urls')),
path('<int:question_id>/',include('myApp.urls')) #path地址
|
|