http://127.0.0.1:8000/my_app/student/my_data/?id=10
We will collect the value of id ( id=10 ) from the URL and display the same.
from django.urls import path
from . import views
# Create your views here.
urlpatterns=[
path('',views.index,name='index'),
path('student/signup_student',views.signup_student,name='signup_student'),
path('student/my_data/',views.my_data,name='md'),
path('student/signup_student_output',views.signup_student_output,name='signup_student_output2'),
path('student/insert_all',views.insert_all,name='insert_all')
]
my_app/views.py
def my_data(request):
id=request.GET.get('id','Not available') # collecting value of id
return render(request,'my_data.html',{'id':id})
We set the path for our template here
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'smo_temp')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Inside our template directory smo_temp, we kept our data.html file.
smo_temp/data.html
{% extends 'temp_basic.html' %}
{% block content %}
Student ID : {{id}}<br>
Student Name : {{name}}
{% endblock %}
http://127.0.0.1:8000/my_app/student/my_data/?id=10&name=Alex%20Ron
views.py
def my_data(request):
id=request.GET.get('id','Not available')
name=request.GET.get('name','Not available')
return render(request,'my_data.html',{'id':id,'name':name})
Output is here
Student ID : 10
Student Name : Alex Ron
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.