sample's People
sample's Issues
Lab pg
views.py
from django.http import HttpResponse
from django.shortcuts import render
from studCourseRegApp.models import student,course, projectForm
Create your views here.
def home(request):
return render(request,'home.html')
def studentlist(request)
s=student.objects.all()
return render(request,'studentlist.html',{'student_list':s})
def courselist(request):
c=course.objects.all()
return render(request,'courselist.html',{'course_list':c})
def register(request):
if request.method=="POST":
sid=request.POST.get("student")
cid=request.POST.get("course")
studentobj=student.objects.get(id=sid)
courseobj=course.objects.get(id=cid)
res=studentobj.courses.filter(id=cid)
if res:
resp="
Student with usn %s has already enrolled for the
%s
"%(studentobj.usn,courseobj.courseCode)
return HttpResponse(resp)
studentobj.courses.add(courseobj)
resp="
student with usn %s successfully enrolled for the course with sub code
%s
"%(studentobj.usn,courseobj.courseCode)return HttpResponse(resp)
else:
studentlist=student.objects.all()
courselist=course.objects.all()
return render(request,'register.html',{'student_list':studentlist,'course_list':courselist})
def enrolledStudents(request):
if request.method=="POST":
cid=request.POST.get("course")
courseobj=course.objects.get(id=cid)
studentlistobj=courseobj.student_set.all()
return render(request,'enrolledlist.html',{'course':courseobj,'student_list':studentlistobj})
else:
courselist=course.objects.all()
return render(request,'enrolledlist.html',{'Course_List':courselist})
urls.py
from django.contrib import admin
from django.urls import path
from studCourseRegApp.views import home, studentlist,courselist,register,enrolledStudents
urlpatterns = [
path('secretadmin/', admin.site.urls),
path('',home),
path('home/',home),
path('studentlist/',studentlist),
path('courselist/',courselist),
path('register/',register),
path('enrolledlist/',enrolledStudents),
]
settings.py(only one change inside installed apps add studCourseRegApp )
Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'studCourseRegApp',
]
OUTPUT
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.