很多時我們想輸出一些特定的headers,而我們之前那些return都無法做到,怎么辦呢,不用那個擔心,bottle框架一早幫我們想好了,他提供了一個response對象,這個對象可以自由處理headers。
~~~
# coding:UTF-8
from bottle import Bottle, response
app = Bottle()
@app.get('/')
def index():
response.set_header("Content-Type", "text/plain")
response.set_header("frame", "this is a bottle")
response.set_header("ownSign", "123")
response.add_header("ownSign", "456")
return "輸出內容"
app.run(host="127.0.0.1", port=8000, reloader=True, debug=True)
~~~
**注意:**
* response不需要return,只需在return之前調用set_header或者add_header方法
* set_header方法在key不存在的時候添加一個key,在key存在的時候覆蓋
* add_header方法無論key是否存在都添加一個key