You are on page 1of 13

AAKKAM

SESSION 10
ADVANCE OPERATION

TODAY’S QUOTES

LEARNING HAPPENS IN THE


MINDS AND SOULS,
NOT IN THE DATABASE
OF
MULTIPLE – CHOICE TESTS

1
AAKKAM

Installation

Pip install matplotlib


Pip install flask-mysql

import matplotlib.pyplot as plt

@app.route("/staffstuanlysis",methods=['POST','GET'])
def staffstuanlysis():
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT `rollno`,`att` FROM `student` ")
stud=cur.fetchall()
rollno=[]
att=[]
for i in stud:
att.append(i[0])
rollno.append(i[1])
plt.plot(rollno,att)
plt.show()
return redirect('staffviewstu')

2
AAKKAM
from flask_qrcode import QRcode
QRcode(app)

@app.route("/studentviewatt")
def studentviewatt():
conn=mysql.connect()
cur=conn.cursor()
stud=request.args.get('id')
cur.execute("SELECT * FROM `student` WHERE `id` ='"+stud+"'")
stud=cur.fetchone()
return render_template("studentviewatt.html",student=stud)

<h1>QR Code</h1>
<img style="margin-left: 50px; margin-top: 60px;" src="{{ qrcode(patient) }}">

3
AAKKAM

For your refer

import os
from flask import Flask,render_template,request,redirect,url_for
from flaskext.mysql import MySQL
import matplotlib.pyplot as plt
from flask_qrcode import QRcode
from werkzeug.utils import secure_filename
app=Flask(__name__)
mysql=MySQL()

QRcode(app)

app.config["MYSQL_DATABASE_USER"]='root'
app.config["MYSQL_DATABASE_PASSWORD"]=''
app.config["MYSQL_DATABASE_DB"]='studentatt'
app.config["MYSQL_DATABASE_HOST"]="localhost"

mysql.init_app(app)

@app.route("/attendence")
def attendence():
return render_template("attendence.html")

@app.route("/adminlogin",methods=['POST','GET'])
def adminlogin():
if request.method=="POST":

4
AAKKAM
username=request.form['username']
password=request.form['pass']
if username=='admin' and password=='admin':
return redirect('adminhome')
else:
error="Invalid"
else:
return render_template("adminlogin.html")

@app.route("/adminhome")
def adminhome():
return render_template("adminhome.html")

@app.route("/adminviewstaff",methods=['POST','GET'])
def adminviewstaff():
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `staff`")
data=cur.fetchall()
return render_template("adminviewstaff.html",staff=data)

@app.route("/adminviewstudent",methods=['POST','GET'])
def adminviewstudent():
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `student`")
data1=cur.fetchall()
return render_template("adminviewstudent.html",student=data1)

5
AAKKAM

@app.route("/stafflogin",methods=['POST','GET'])
def stafflogin():
if request.method=="POST":
username=request.form['username']
password=request.form['pass']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `staff` WHERE `username` ='"+username+"' and `passwor
d` = '"+password+"'")
data=cur.fetchone()
if data[5]==username and data[6]==password:
return redirect('staffhome')
else:
error ="invalid"
else:
return render_template("stafflogin.html")

@app.route("/staffhome")
def staffhome():
return render_template("staffhome.html")

@app.route("/staffaddstu",methods=['POST','GET'])
def staffaddstu():
if request.method=="POST":
name=request.form['name']
rollno=request.form['rollno']
phno=request.form['phno']
email=request.form['email']

6
AAKKAM
gender=request.form['gender']
fathername=request.form['fathername']
address=request.form['address']
dept=request.form['dept']
APP_PATH_ROUTE=os.path.dirname(os.path.abspath(__file__))
target=os.path.join(APP_PATH_ROUTE,'uploads')
UPLOAD_FOLDER='{}/static/uploads/'.format(APP_PATH_ROUTE)
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER
files=request.files['files']
f=os.path.join(UPLOAD_FOLDER,files.filename)
files.save(f)
filename=secure_filename(files.filename)
conn=mysql.connect()
cur=conn.cursor()
cur.execute("INSERT INTO `student`( `name`, `rollno`, `phno`, `email`, `gender`, `fatherna
me`, `address`, `dept`, `image`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)",(name,rollno,phno,
email,gender,fathername,address,dept,filename))
conn.commit()
return redirect('staffviewstu')
else:
return render_template("staffaddstu.html")

@app.route("/staffviewstu",methods=['POST','GET'])
def staffviewstu():
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `student`")
data2=cur.fetchall()
return render_template("staffviewstu.html",student=data2)

7
AAKKAM

@app.route("/staffstuanlysis",methods=['POST','GET'])
def staffstuanlysis():
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT `rollno`,`att` FROM `student` ")
stud=cur.fetchall()
rollno=[]
att=[]
for i in stud:
att.append(i[0])
rollno.append(i[1])
plt.plot(rollno,att)
plt.show()
return redirect('staffviewstu')

@app.route("/staffregister",methods=['POST','GET'])
def staffregister():
if request.method=="POST":
title=request.form['title']
name=request.form['name']
email=request.form['email']
phno=request.form['phno']
username=request.form['username']
password=request.form['password']
gender=request.form['gender']
conn=mysql.connect()
cur=conn.cursor()

8
AAKKAM
cur.execute("INSERT INTO `staff`(`title`, `name`, `email`, `phno`, `username`, `password`,
`gender`) VALUES (%s,%s,%s,%s,%s,%s,%s)",(title,name,email,phno,username,password,gen
der))
conn.commit()
return redirect('stafflogin')
else:
return render_template("staffregister.html")

@app.route("/studentlogin",methods=['POST','GET'])
def studentlogin():
if request.method=="POST":
rollno=request.form['rollno']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `student` WHERE `rollno` ='"+rollno+"'")
data=cur.fetchone()
if data[2]==rollno:
return redirect(url_for('studenthome',id=data[0]))
else:
error ="invalid"
else:
return render_template("studentlogin.html")

@app.route("/updatestu",methods=['POST','GET'])
def updatestu():
conn=mysql.connect()
cur=conn.cursor()
studentid=request.args.get('id')
cur.execute("SELECT * FROM `student` WHERE `id` ='"+studentid+"'")

9
AAKKAM
stu1=cur.fetchone()
if request.method=="POST":
name=request.form['name']
rollno=request.form['rollno']
phno=request.form['phno']
email=request.form['email']
gender=request.form['gender']
fathername=request.form['fathername']
address=request.form['address']
dept=request.form['dept']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("UPDATE `student` SET `name`='"+name+"',`rollno`='"+rollno+"',`phno`='"+p
hno+"',`email`='"+email+"',`gender`='"+gender+"',`fathername`='"+fathername+"',`address`='"+a
ddress+"',`dept`='"+dept+"' WHERE `id` ='"+studentid+"' ")
conn.commit()
return redirect('staffviewstu')
else:
return render_template("updatestu.html",stu=stu1)

@app.route("/updatestaff",methods=['POST','GET'])
def updatestaff():
conn=mysql.connect()
cur=conn.cursor()
staffid=request.args.get('id')
cur.execute("SELECT * FROM `staff` WHERE `id` ='"+staffid+"'")
stf1=cur.fetchone()
if request.method=="POST":
title=request.form['title']

10
AAKKAM
name=request.form['name']
email=request.form['email']
phno=request.form['phno']
username=request.form['username']
password=request.form['password']
gender=request.form['gender']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("UPDATE `staff` SET `title`='"+title+"',`name`='"+name+"',`phno`='"+phno+"'
,`email`='"+email+"',`gender`='"+gender+"',`username`='"+username+"',`password`='"+passwor
d+"' WHERE `id` ='"+staffid+"' ")
conn.commit()
return redirect('adminviewstaff')
else:
return render_template("updatestaff.html",stf=stf1)

@app.route("/deletestaff",methods=['POST','GET'])
def deletestaff():
conn=mysql.connect()
cur=conn.cursor()
staffid=request.args.get('id')
cur.execute("DELETE FROM `staff` WHERE `id` ='"+staffid+"'")
conn.commit()
return redirect('adminviewstaff')

@app.route("/upattendence",methods=['POST','GET'])
def upattendence():
conn=mysql.connect()
cur=conn.cursor()

11
AAKKAM
studid=request.args.get('id')
cur.execute("SELECT * FROM `student` WHERE `id` ='"+studid+"'")
stu2=cur.fetchone()
if request.method=="POST":
att=request.form['att']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("UPDATE `student` SET `att`='"+att+"' WHERE `id` ='"+studid+"' ")
conn.commit()
return redirect('staffviewstu')
else:
return render_template("upattendence.html",stu=stu2)

@app.route("/studenthome",methods=['POST','GET'])
def studenthome():
stuid=request.args.get('id')
return render_template("studenthome.html",student=stuid)

@app.route("/studentprofile")
def studentprofile():
conn=mysql.connect()
cur=conn.cursor()
stud=request.args.get('id')
cur.execute("SELECT * FROM `student` WHERE `id` ='"+stud+"'")
stu3=cur.fetchone()
return render_template("studentprofile.html",student=stu3)

@app.route("/studentviewatt")

12
AAKKAM
def studentviewatt():
conn=mysql.connect()
cur=conn.cursor()
stud=request.args.get('id')
cur.execute("SELECT * FROM `student` WHERE `id` ='"+stud+"'")
stud=cur.fetchone()
return render_template("studentviewatt.html",student=stud)

if(__name__=="__main__"):
app.run(debug=True)

13

You might also like