import bottle
from bottle import template, Bottle, static_file, request, redirect
bottle.TEMPLATE_PATH.append("./templates/") # 指定模板目錄
root = Bottle()
@root.route("/index", method=["GET", "POST"])#method 默認GET,可以指定其他請求或者請求方式列表
def index():
print (request.method) #POST
print (request.forms) #post請求信息
print (request.query) #get 請求數(shù)據(jù)
print (request.body) #POST 請求數(shù)據(jù)
print (request.files) #上傳的文件信息
print (request.cookies) #cookie信息
print (request.environ) #環(huán)境信息
print (request.json) #
print (request.params) #
if request.method == "GET":
return template("<h1> Hello {{ name }}</h1>", name="Bottle")
elif request.method == "POST":
return redirect("/index/")
@root.route("/static/<path:path>")
def callback(path):
return static_file(path, "static") #指定靜態(tài)文件目錄static
root.run(host="localhost", port=8080)
python 之bottle簡單使用
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。