This repository was archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (47 loc) · 1.77 KB
/
app.py
File metadata and controls
57 lines (47 loc) · 1.77 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
49
50
51
52
53
54
55
56
57
import os
from flask import Flask, render_template, request
# App Logic
app = Flask(__name__)
@app.route('/database_form')
def index():
# DATABASE OPTIONS GO HERE
# this list supplies the options that are generated in the home page selector
# to add or remove entries from home page selector, put them in the list SELECTOR_OPTIONS below
SELECTOR_OPTIONS = ['database_1', 'database_2', 'database_3']
return render_template('index.html', selector_options = SELECTOR_OPTIONS )
@app.route('/404')
def not_found():
return render_template('404.html')
@app.route('/charts')
def charts():
return render_template('charts.html')
@app.route('/tables')
def tables():
return render_template('tables.html')
@app.route('/submit_form', methods=['GET', 'POST'])
def submit_form():
database_name = request.form.get('database_selection')
# HERE YOUR ACTION CAN BE DONE TO YOUR DATABASE
# we can access the database name from our form by database_name variable
# We can connect to our database via python library, example:
# connection = mysql.connector.connect(
# host=host_name,
# user=user_name,
# passwd=user_password,
# database=database_name
# )
# select_users = "SELECT * from users"
# connection.autocommit = True
# cursor = connection.cursor()
# try:
# cursor.execute(query)
# result = 'Success!'
# except OperationalError as e:
# result = 'Operation Failure'
result = 'Success!'
return render_template('submit_form.html', selected_database = database_name, result = result)
@app.route('/')
def example_sb_admin_home():
return render_template('example.html')
if __name__ == '__main__':
app.run()