丟個FLASK紀錄一下
from flask import Flask, render_template, url_for, redirect, request
app = Flask(__name__)
app.config["ENV"] = "development"
app.config["DEBUG"] = True
@app.route("/")
def index():
return render_template("index.html")
@app.route("/test", methods=["GET", "POST"])
def test():
return request(url_for("index"))
"""
@app.route("/test1")
def index():
return render_template("index.html")
"""
@app.route("/test2")
def test2():
return redirect(url_for("index"))
@app.route("/test3/<int:a>/<int:b>")
def test3(a, b):
return str(a + b)
@app.route("/test4")
def test4():
return request.args.get('abc')
"""
@app.route('/text5', methods=['POST'])
def JSON_value():
if request.is_json:
data = request.get_json()
result = data.get('def', None)
result = data.get('pi', None)
result = data.get('abc', None)
else:
result = 'Not JSON Data'
return result
"""
@app.errorhandler(404)
def page_not_found(error):
return render_template('page_not_found.html'), 404
if __name__ == "__main__":
app.run()