Sunday, March 14, 2021

django day 5 view page logic

View.py ===================== from django.shortcuts import render from django.http import HttpResponse # Create your views here. def home(request): #1+2 #HttpResponse("

this is homepage

") #return HttpResponse("

this is test2 app homepage

") user="ranjith" context={'name':user} if user == "chandu": #context={'name':user} return render(request, "home.html", context) elif user == "ranjith": return render(request, "contact.html", {'price':1000}) else: return render(request, "home.html", context) def contact(request): return HttpResponse("

this is app contactpage

") contact.html =========================

HTML Table

Company Contact price
Alfreds Futterkiste Maria Anders {{price}}
Centro comercial Moctezuma Francisco Chang {{price}}
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy
urls.py =================================== from django.contrib import admin from django.urls import path,include from . import views urlpatterns = [ path('',views.home,name="home"), path('contact',views.contact,name="contact") ]

python class topic video