-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (40 loc) · 1.21 KB
/
app.py
File metadata and controls
49 lines (40 loc) · 1.21 KB
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
from flask import Flask, render_template, request, redirect, url_for
import sqlite3
app = Flask(__name__)
# Connect to DB and create table (run once)
def init_db():
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS joining_form (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT,
phone TEXT
-- Add other fields as per your form
)
''')
conn.commit()
conn.close()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/nomination')
def nomination():
return render_template('nomination_form.html')
@app.route('/submit', methods=['POST'])
def submit():
name = request.form['name']
email = request.form['email']
phone = request.form['phone']
# Fetch other form fields similarly
# Save to database
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
cursor.execute("INSERT INTO joining_form (name, email, phone) VALUES (?, ?, ?)", (name, email, phone))
conn.commit()
conn.close()
return redirect(url_for('nomination'))
if __name__ == '__main__':
init_db()
app.run(debug=True)