-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (50 loc) · 1.81 KB
/
app.py
File metadata and controls
76 lines (50 loc) · 1.81 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
'''
sample code to learn Flask
This code is designed to run in cloud9.
From the terminal, run:
$ python app.py
and then start a preview
Debugging should be turned off for deployment but this code
may be used for testing on a local machine.
'''
import arrow
from flask import (
Flask, g, session, flash, render_template,
request, url_for, redirect, jsonify
)
from functools import wraps
import json
import math, random
import os
# this is a hard-coded example for demo purposes
APP_SECRET_KEY = "this is a secret" # change for production
app = Flask(__name__)
app.debug = True
app.secret_key = APP_SECRET_KEY # hard-coded for demo
# this code creates a ROUTE.
# A route is connected to a URL.
@app.route("/", methods=["GET"])
def home():
return "Welcome to the app!"
@app.route("/demo", methods=["GET"])
def demo():
list_name = "Day 1 Vocabulary"
needs_work = ["git init", "pip", "asynchronous"]
return render_template("demo.html", list_name=list_name, needs_work=needs_work)
@app.route("/progress", methods=["GET"])
def progress():
# here is a Python variable named `the_message`
the_message = "Hello! This is the progress page!"
# Look carefully at the items in parentheses here:
return render_template("progress.html", the_message=the_message)
# Don't worry about the code below this line --
# this is some fancy stuff which enables us to
# view error messages in the browser.
if __name__ == "__main__":
app.config["PROPAGATE_EXCEPTIONS"] = True
app.config["DEBUG"] = True
''' next line: cause KeyErrors to bubble up to top level
so we can see the traceback & debugger '''
app.config["TRAP_BAD_REQUEST_ERRORS"] = True
app.run(host=os.getenv('IP', '0.0.0.0'),port=int(os.getenv('PORT', 8080)))