-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
32 lines (28 loc) · 1.11 KB
/
server.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
from flask import Flask, render_template, request
import sqlite3
app = Flask( __name__ )
@app.route( '/' )
def home():
return render_template( 'home.html' )
@app.route( '/enterfood' )
def enternew():
return render_template( 'food.html' )
@app.route( '/addfood', methods = [ 'POST' ] )
def addfood():
connection = sqlite3.connect( 'database.db' )
cursor = connection.cursor()
try:
name = request.form[ 'name' ]
calories = request.form[ 'calories' ]
cuisine = request.form[ 'cuisine' ]
is_vegetarian = request.form[ 'is_vegetarian' ]
is_gluten_free = request.form[ 'is_gluten_free' ]
cursor.execute( 'INSERT INTO foods( name, calories, cuisine, is_vegetarian, is_gluten_free ) VALUES ( ?, ?, ?, ?, ? )', ( name, calories, cuisine, is_vegetarian, is_gluten_free ) )
connection.commit()
message = 'Record successfully added'
except:
connection.rollback()
message = 'error in insert operation'
finally:
return render_template( 'result.html', message = message )
connection.close()