forked from fzsun/BFL-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapp.py
45 lines (36 loc) · 1.17 KB
/
myapp.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 30 21:01:11 2018
@author: Fangzhou Sun
"""
import os
import jinja2
from flask import Flask, render_template, request, send_from_directory, jsonify
from algorithm.tsp import tsp
app = Flask(__name__, template_folder='')
# ============== Page Rendering ==============
@app.route('/')
def root():
return render_template('index.html')
@app.route('/<path:subpath>/')
def static_html(subpath):
"""all htmls that do not need extra code in Flask"""
return render_template(f'static_html/{subpath}.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path,'static'),'favicon.ico')
@app.errorhandler(404)
@app.errorhandler(jinja2.exceptions.TemplateNotFound)
def page_not_found(e):
return render_template('404.html'), 404
# ============== POST Actions ==============
@app.route('/tsp/action/', methods=['POST'])
def render_tsp():
n = request.form['num_cities']
my_tsp = tsp()
my_tsp.from_num_cities(int(n))
my_tsp.solve()
return jsonify(my_tsp.all_data_)
if __name__ == '__main__':
app.run(debug=True, port=5000) # Note: development server only