-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-bkp.py
104 lines (75 loc) · 2.82 KB
/
app-bkp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from flask import Flask, flash, render_template, request, session, redirect, url_for, escape
from flaskext.mysql import MySQL
app=Flask(__name__)
app.secret_key = 'note'
mysql = MySQL(app)
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = ''
app.config['MYSQL_DATABASE_DB'] = 'note'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
@app.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST':
title = request.form['title']
description = request.form['description']
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("INSERT INTO details (title,description)VALUES('"+title+"','"+description+"')")
conn.commit()
return redirect(url_for('viewurl'))
return render_template('index.html')
@app.route('/searchurl', methods=['GET','POST'])
def searchurl():
if request.method == 'POST':
title = request.form['title']
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("select title,description,nid from details where title like = '"%title%"'")
rows = cursor.fetchall()
return render_template('viewurl.html', data = rows)
return render_template('searchurl.html')
@app.route('/viewurl')
def viewurl():
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("select title,description,nid from details")
rows = cursor.fetchall()
return render_template('viewurl.html', data = rows)
@app.route('/delnote/<nid>', methods=['GET','POST'])
def delnote_entry(nid):
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("delete from details where nid ='"+nid+"'")
conn.commit()
return redirect(url_for('viewurl'))
@app.route('/editnote/<nid>', methods=['GET','POST'])
def editnote_entry(nid):
#if request.method == 'POST':
#nid = request.form['nid']
#title = request.form['title']
#description = request.form['description']
#conn = mysql.connect()
#cursor = conn.cursor()
#cursor.execute("update details set title='"+title+"',description='"+description+"' where nid='"+nid+"'")
#conn.commit()
#return redirect(url_for('viewurl'))
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("select title,description,nid from details where nid='"+nid+"'")
rows = cursor.fetchall()
return render_template('editnote.html', data = rows)
if request.method == 'POST':
nid1 = request.form['nid1']
title = request.form['title']
description = request.form['description']
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("update details set title='"+title+"',description='"+description+"' where nid='2'")
conn.commit()
return redirect(url_for('viewurl'))
return redirect(url_for('viewurl'))
if __name__=="__main__":
app.debug = True
app.run()
app.run(debug = True)