repl.it
@timmy_i_chen/

flask guestbook-starter

Python

a simple guestbook written in flask

fork
loading
Files
  • main.py
  • static
  • templates
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
30
31
32
from flask import Flask, render_template, request, jsonify
app = Flask('app')

# GET requests - asking for thing
# POST requests - changing a thing

messages = [
  { "name": "Tim", "message": "Hello!" },
  { "name": "Carol", "message": "Sup!" }
]

@app.route('/')
def index():
  return render_template('index.html', messages=messages)

@app.route('/sign', methods=['POST'])
def sign():
  print("someone signed the book")
  name = request.form["name"]
  message = request.form["message"]

  messages.append({
    "name": name,
    "message": message
  })
  return "it worked"

@app.route('/messages')
def get_messages():
  return jsonify(messages)

app.run(host='0.0.0.0', port=8080)