-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
29 lines (22 loc) · 748 Bytes
/
main.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
from flask import Flask, render_template, request, redirect, url_for
import csv
app = Flask(__name__)
# Define the path to the CSV file
csv_file = 'data.csv'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods=['POST'])
def submit():
if request.method == 'POST':
name = request.form['name']
age = request.form['age']
city = request.form['city']
phone = request.form['phone']
# Append the data to the CSV file
with open(csv_file, mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([name, age, city, phone])
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)