Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!coding=utf-8
  2. import os
  3. import json
  4.  
  5. from flask import Flask
  6. from flask import request
  7. from flask import render_template
  8. from flask import jsonify
  9.  
  10.  
  11. current_dir = os.path.abspath('.')
  12. app = Flask(__name__, template_folder=current_dir)
  13.  
  14.  
  15. @app.route('/xxx')
  16. def get_map():
  17.     return render_template('xxx.html')
  18.  
  19.  
  20. @app.route('/edit', methods=['POST'])
  21. def post_edit():
  22.     params = request.get_json()
  23.     param1 = params.get('param1')
  24.     param2 = params.get('param2')
  25.     # your code here
  26.     debug_data = [
  27.         ['./static/flower.png', './static/flower.png'],
  28.         ['./static/flower.png', './static/flower.png'],
  29.         ['./static/flower.png', './static/flower.png'],
  30.     ]
  31.     debug_points = [
  32.         [10, 10],
  33.         [10, 50],
  34.         [50, 200],
  35.         [50, 10],
  36.     ]
  37.     expected_data = {
  38.         'images': debug_data,
  39.         'points': debug_points,
  40.     }
  41.     return jsonify(expected_data)
  42.  
  43.  
  44. @app.route('/edit')
  45. def get_edit():
  46.     # param1 = int(request.args.get('param1'))        # 这个已经是int了
  47.     # param2 = json.loads(request.args.get('param2')) # 这个已经是数组了
  48.     debug_data = [
  49.         ['./static/flower.png', './static/flower.png'],
  50.         ['./static/flower.png', './static/flower.png'],
  51.         ['./static/flower.png', './static/flower.png', './static/flower.png'],
  52.     ]
  53.     debug_points = [
  54.         [10, 10],
  55.         [10, 50],
  56.         [50, 50],
  57.         [50, 10],
  58.     ]
  59.     expected_data = {
  60.         'images': debug_data,
  61.         'points': debug_points,
  62.     }
  63.     return render_template('map.html', rows=debug_data, points=debug_points)  # 渲染html页面
  64.  
  65.  
  66. if __name__ == '__main__':
  67.     app.run(
  68.         debug=True,
  69.         host='0.0.0.0',
  70.         port=3000,
  71.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement