from django.urls import include, path
from.import views
urlpatterns = [
path('student/display/',views.display,name='display')
]
http://127.0.0.1:8000/student/display/
When we use above url, our url page inside student app will run views.py using display function. def display(request):
id=request.GET.get('id', 'Not available')
if(id != 'Not available'):
st=student.objects.get(id=id)
return render(request,'details.html',{'st':st})
else:
st=student.objects.all().order_by('id')[5:10]
return render(request,'list.html',{'st':st})
Here we can see if the value of id is not available ( id='Not available' ) then list.html is used and if id value is available then details.html is used. st=student.objects.all().order_by('id')[5:10]
to generate one QuerySet with records from id 6 to 10, this line can be changed to get different set of records by using filters. {% extends 'temp_basic.html' %}
{% block content %}
{% for sts in st %}
<a href=?id={{sts.id}}>{{sts.name}}</a><br>
{% endfor %}
{% endblock %}
details.html
{{st.id}},{{st.name}},{{st.cl}},{{st.mark}},{{st.gender}}
<br>
<a href=./>Back</a>
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.