DYNAMIC URL WITH SOME STUDENT INFORMATION (PART-2)

                                                    SOB SAME THAKBE SUDHU



VIEW PART


from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
# Create your views here.


def initial(request):
    return render(request,'dynamic\initial.html')

def index(request,my_id):
    if my_id == 1: #OR URL <STR> HOLE 1 NA LIKHE '1' AIVABE LIKHBO
      dict={'name':"Munna" , 'id':'181' , 'number':my_id , 'uni':'Daffodil'}
    
    if my_id == 2:
      dict={'name':"Wkramul" , 'id':'182' , 'number':my_id , 'uni':'NORTH SOUTH'}

    if my_id == 3:
      dict={'name':"MOFIZ" , 'id':'183' , 'number':my_id , 'uni':'BUET'}
    
    
    return render(request,'dynamic\index.html',dict)



URL PART

from . views import index
from django.urls import path
from . import views

urlpatterns = [

    
    path('index/<int:my_id>/',views.index,name='index_name'),
    path('initial/',views.initial,name='initial_name')    

]


HTML 1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <h1> ITS MY INITIAL PAGE </h1>

    <a href="{% url 'index_name' 1 %}">STUDENT 1</a>
    <a href="{% url 'index_name' 2 %}">STUDENT 2</a>
    <a href="{% url 'index_name' 3 %}">STUDENT 3</a>




</body>
</html>


HTML 2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
      
    <P> INFORMATION </P>
    <br>
    <p>NAME : {{name}}</p>
    <p>ID : {{id}}</p>
    <p>UNIVERSITY : {{uni}}</p>
    <p>NUMBER:{{number}}</p>
    <br>
    <a href="{% url 'initial_name' %}">Back to home</a>
</body>
</html>



Comments

Popular posts from this blog

D WEB LINK