-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
75 lines (60 loc) · 2.26 KB
/
app.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
from flask import Flask
from flask import render_template, request, jsonify, Response
from flask_cache_buster import CacheBuster
#from flask_sqlalchemy import SQLAlchemy
import os
config = {
'extensions': ['.js', '.css', '.csv'],
'hash_size': 10
}
#configure an extension used to bust caches
cache_buster = CacheBuster(config=config)
#create a flask application and tell it where the 'templates' and 'static' folders are
#flask uses a particular project structure that expects the following:
# app.py
# |--static
# |-- resources to be used by templates
# |--templates
# |-- html templates to rendered by the flask app
app = Flask(__name__, template_folder='./templates', static_folder='./static')
'''
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///ktask_demo'
db = SQLAlchemy(app)
class Exp_Data(db.Model):
id = db.Column('participant_id', db.Integer, primary_key = True)
name = db.Column(db.String(100))
trial = db.Column(db.Integer)
trial_rt = db.Column(db.Integer)
trial_acc = db.Column(db.Integer)
def __init__(self, name, trial, trial_rt,trial_acc):
self.name = name
self.trial = trial
self.trial_rt = trial_rt
self.trial_acc = trial_acc
'''
#if resources have been updated, use the most recent resources instead of old cached resources
cache_buster.register_cache_buster(app)
#set a route for the load screen
@app.route("/")
def home():
#load the file 'home.html' from the templates folder
#to render a template outside of the templates folder, specifcy a different folder in
#app = Flask(... , template_folder=<your new folder>, ...)
return render_template("home.html")
'''
@app.route("/data", methods=['GET','POST'])
def store_data(request):
if request.method == 'POST':
if not request.form['name']:
flash('Please enter your name', 'error')
else:
data = Exp_Data(request.form['name'], request.form['trial'],
request.form['trial_rt'], request.form['trial_acc'])
db.session.add(data)
db.session.commit()
flash('Record was successfully added')
return redirect(url_for('home'))
'''
if __name__ == "__main__":
from os import environ
app.run(debug=False, port=environ.get("PORT", 33507), processes=2)