Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tutorial Python code
- import os
- from flask import Flask, render_template
- app = Flask(__name__)
- @app.route("/")
- def index():
- return render_template("index.html", message = "Hello Flask!", contacts = ['c1', 'c2', 'c3', 'c4', 'c5']);
- if __name__ == "__main__":
- app.run()
- // Corresponding Tutorial HTML
- <!DOCTYPE html>
- <html>
- <head>
- <title>Flask Template Example</title>
- </head>
- <body>
- <div>
- <p>{{ message }}</p>
- <p>{{ contacts }}</p>
- <p>My Contacts:</p>
- <ul>
- {% for contact in contacts %}
- <li>{{ contact }}</li>
- {% endfor %}
- </ul>
- </div>
- </body>
- </html>
- // Second tutorial Python, two @app.route
- import sys
- from flask import Flask, render_template, request, redirect, Response
- import random, json
- app = Flask(__name__)
- @app.route('/')
- def output():
- return render_template('index.html', name='Joe')
- @app.route('/reciever', methods = ['POST'])
- def worker():
- data = request.get_json()
- result = ''
- for item in data:
- result += str(item['make']) + 'n'
- return result
- if __name__ == "__main__":
- app.run()
- // JavaScript communication first attempt (I was sending them to the second tutorial's Python code)
- var sentArray = {"array" : [key, start, finish, holdtime, ud, uu, dd, 1]};
- $.post("reciever",sentArray,function(){
- });
- event.preventDefault();
- // JavaScript communication second attempt
- var sentArray = {"array" : [key, start, finish, holdtime, ud, uu, dd, 1]};
- fetch('/typing', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- }
- body:
- {"array" : [key, start, finish, holdtime, ud, uu, dd, 1]}
- }
- });
- event.preventDefault();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement