Dajngo (Day 4)
Create a Directory named "Templates" in main folder
Create a HTML File in it
Add {{ students }} line in Body
in django_project/settings.py update Templates[]:
'DIRS': [BASE_DIR / 'templates'],
Update test_app/urls.py
from django.urls import path
from test_app import views
urlpatterns = [
path('student', views.index, name='students'),
path('student/<int:pk>/', views.get_student, name='student'),
]
Update test_app/views.py
from django.http import HttpResponse
from django.shortcuts import render
from .models import Student
def index(request):
std=Student.objects.all()
return render(request,'index.html',{'students':std})
def get_student(request,pk):
std=Student.objects.get(id=pk)
return render(request,'index.html',{'students':std})
Run Server: python manage.py runserver
8000/admin
Add a new student in the Table Student
Now Change the Link
8000/api/student/1/
You have to see the name of the student 1
Code Successfull
Note: Any Doubts Contact Hemanth Sir
Comments
Post a Comment