forked from orbit-oss/flask
add javascript ajax example
This commit is contained in:
parent
d8bf589d48
commit
fce1885f76
21 changed files with 341 additions and 13 deletions
16
examples/javascript/js_example/views.py
Normal file
16
examples/javascript/js_example/views.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from flask import jsonify, render_template, request
|
||||
|
||||
from js_example import app
|
||||
|
||||
|
||||
@app.route('/', defaults={'js': 'plain'})
|
||||
@app.route('/<any(plain, jquery, fetch):js>')
|
||||
def index(js):
|
||||
return render_template('{0}.html'.format(js), js=js)
|
||||
|
||||
|
||||
@app.route('/add', methods=['POST'])
|
||||
def add():
|
||||
a = request.form.get('a', 0, type=float)
|
||||
b = request.form.get('b', 0, type=float)
|
||||
return jsonify(result=a + b)
|
||||
Loading…
Add table
Add a link
Reference in a new issue