Flask學(xué)習(xí)文檔

1.對(duì)比Django

比較項(xiàng) Django Flask 復(fù)雜度比較 說明
項(xiàng)目創(chuàng)建 Django需要用命令創(chuàng)建項(xiàng)目 Flask直接編寫文件就可以運(yùn)行 Django復(fù)雜 Django需要用命令創(chuàng)建項(xiàng)目是因?yàn)樾枰獎(jiǎng)?chuàng)建整個(gè)項(xiàng)目框架
路由 Django使用專門的urls.py Flask直接使用@app.route() Django笨重 Django類似Struct2的配置崖叫,F(xiàn)lask類似Spring的配置纫骑,F(xiàn)lask感覺更好
GET和POST request.GET['name']和request.POST['name'] request.args.get("name","")和request.form["q"] 差不多 Flask上格式不統(tǒng)一
Restful 使用django-restful框架 使用flask-restful框架 差不多 Flask使用方法flask-restfu使用類格式不統(tǒng)一;flask-restful需要注冊(cè)參數(shù)
數(shù)據(jù)庫操作 django集成了對(duì)數(shù)據(jù)庫的操作 Flask沒集成對(duì)數(shù)據(jù)庫的操作要另行 差不多 django復(fù)雜很大程度來源于對(duì)于數(shù)據(jù)庫的集成

Django繼承了MVT和ORM,以及后臺(tái)管理。

Flask兩個(gè)主要核心應(yīng)用是EWerkzeug和模板引擎jinja2。

擴(kuò)展包

Flask Django
Flask-SQLalchemy 操作數(shù)據(jù)庫 django-admin
Flask-migrate 管理遷移數(shù)據(jù)庫 manage.py
Flask-Mail 郵件 orm模型
Flask-WTF 表單 admin
Flask-script 插入腳本 文件存儲(chǔ)系統(tǒng)
Flask-OpenID 認(rèn)證 用戶認(rèn)證系統(tǒng)
Flask-Login 認(rèn)證用戶狀態(tài)
Flask-RESTful 開發(fā)REST API的工具
Flask-Bootstrap 集成前端Twiiter Bootstrap框架
Flask-Moment 本地化日期和時(shí)間

Django內(nèi)容 Flsak都沒有需要擴(kuò)展包提供 框架核心 : Werkzerug + jinja2(輕)

2.安裝

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="shell" cid="n103" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">pip3 install flask</pre>

第一個(gè)項(xiàng)目

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n106" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"># --UTF-8--

-lv wq --

導(dǎo)入Flask類

from flask import Flask

Flask類接收一個(gè)參數(shù)name

app = Flask(name)

裝飾器的作用是將路由映射到視圖函數(shù)index

@app.route('/')
def index():
return "hello,world"

Flask 應(yīng)用程序?qū)嵗膔un方法啟動(dòng)web服務(wù)器

if name == 'main':
app.run()</pre>

Flask對(duì)象的初始化參數(shù)

應(yīng)用程序配置參數(shù)

app.run()運(yùn)行參數(shù)

應(yīng)用程序配置參數(shù)

Django將所有配置信息都放到了settings.py文件中,而Flask則不同楞卡。

Flask將配置信息保存到了app.config 屬性中,該屬性可以按照字典類型進(jìn)行操作宛琅。

讀取

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n115" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">from flask import Flask
app = Flask(name)
app.config.get(name)
app.config[name]</pre>

設(shè)置

1.從配置對(duì)象中加載

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n118" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app.config.from_object(配置對(duì)象)</pre>

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n119" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">class DefaultConfig(object):
"""
默認(rèn)配置
"""
SECRET_KEY = 'TPmi4aLWRbyVq8zu9v82dWYW1'
app = Flask(name)
app.config.from_object(DefaultConfig)

@app.route("/")
def index():
print(app.config['SECRET_KEY'])
return 'HELLO World'

應(yīng)用場(chǎng)景刻蟹,可以繼承---------------------------------------

class DevelopmentConfig(DefaultConfig):
DEBUG=True</pre>

例子:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n121" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"># --UTF-8--

-lv wq --

導(dǎo)入Flask類

from flask import Flask
class DefaultConfig(object):
"""默認(rèn)配置"""
SECRET_KEY = 'CHDWDIJQIDQWDQW123DKWENFF33'

Flask類接收一個(gè)參數(shù)name

app = Flask(name)
app.config.from_object(DefaultConfig) #
裝飾器的作用是將路由映射到視圖函數(shù)index
@app.route('/')
def index():
print(app.config['SECRET_KEY'])
return "hello,world"

Flask 應(yīng)用程序?qū)嵗膔un方法啟動(dòng)web服務(wù)器

if name == 'main':
app.run()</pre>

2.從配置文件中加載

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n123" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app.config.from_pyfile(配置文件)</pre>

新建一個(gè)配置文件setting.py

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n125" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">SECRET_KEY = 'TPmi4aLWRbyVq8zu9v82dWYW1'</pre>

在Flask程序文件中

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n127" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app = Flask(name
app.config.from_pyfile('setting.py')

@app.route("/")
def index():
print(app.config['SECRET_KEY'])
return "hello world"</pre>

例子:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n129" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"># --UTF-8--

-lv wq --

導(dǎo)入Flask類

from flask import Flask
app = Flask(name)
app.config.from_pyfile('settings.py')

裝飾器的作用是將路由映射到視圖函數(shù)index

@app.route('/')
def index():
print(app.config['SECRET_KEY'])
return "hello,world"

Flask 應(yīng)用程序?qū)嵗膔un方法啟動(dòng)web服務(wù)器

if name == 'main':
app.run()</pre>

3.從環(huán)境變量中加載

Flask使用環(huán)境變量加載配置的本質(zhì)是通過環(huán)境變量值找到配置文件,再讀取配置文件的信息嘿辟,其使用方式為

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n134" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app.config.from_envvar('環(huán)境變量名') # 環(huán)境變量值為配置文件的絕對(duì)路徑 </pre>

先在終端中執(zhí)行如下命令

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n136" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">export PROJECT_SETTING = '~/setting.py'</pre>

再運(yùn)行代碼

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n138" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app = Flask(name)
app.config.from_envvar('PROJECT_SETTING',silent=True)

@app.route("/")
def index():
print(app.config['SECRET_KEY'])
return "hello world"
if name == 'main':
app.run(host="0.0.0.0",port=5000,debug=True) # 指定運(yùn)行的主機(jī)IP端口和是否開啟DEBUG</pre>

表示系統(tǒng)環(huán)境變量中沒有設(shè)置相應(yīng)值時(shí)是否拋出異常 False 表示不安靜的處理舆瘪,沒有值時(shí)報(bào)錯(cuò)通知,默認(rèn)為False,True 表示安靜的處理红伦,即時(shí)沒有值也讓Flask正常的運(yùn)行下去

3.開發(fā)服務(wù)器啟動(dòng)方式

從1.0版本開始 不再需要在 代碼中寫 app.run()

使用命令 flask run

4.路由

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n145" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@app.route("/login")
def view_func():
return "hello world"</pre>

1.查詢路由信息

--命令行方式

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n148" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">flask routes</pre>

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n150" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Endpoint Methods Rule


index GET /
static GET /static/</pre>

--在程序中獲得

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n152" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">print(app.url_map)</pre>

也可以遍歷路由信息

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n154" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">for rule in app.url_map-iter_rules():
print('name = {} path = {}'.format(rule.endpoint,rule.rule))</pre>

2.獲取請(qǐng)求參數(shù)

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n156" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">from flask import request</pre>

屬性 說明 類型
data 記錄請(qǐng)求數(shù)據(jù)英古,并轉(zhuǎn)換為字符串 *
form 記錄請(qǐng)求中的表單數(shù)據(jù) MultiDict
args 記錄請(qǐng)求中的查詢參數(shù) MultiDict
coockies 記錄請(qǐng)求中的cookie信息 Dict
headers 記錄請(qǐng)求中的報(bào)文頭 EnvironHeaders
method 記錄請(qǐng)求使用的HTTP方法 GET/POST
url 記錄請(qǐng)求的URL地址 String
files 記錄請(qǐng)求上傳的文件 *

5.請(qǐng)求鉤子

請(qǐng)求鉤子是通過裝飾器的形式實(shí)現(xiàn),F(xiàn)lask支持四種請(qǐng)求鉤子:

before_first_request : 在處理第一個(gè)請(qǐng)求前運(yùn)行昙读。

before_request : 在每次請(qǐng)求前運(yùn)行

after_request : 如果沒有未處理的異常拋出召调,在每次請(qǐng)求后運(yùn)行。

teatrdown_request : 在每次請(qǐng)求后運(yùn)行蛮浑,即使有未處理的異常拋出

6.JinJa2模板

http://docs.jinkan.org/docs/jinja2/

Flask使用Jinja2這個(gè)模板引擎來渲染模板唠叛。Jinja2能識(shí)別所有類型的變量,包括{}沮稚。 Jinja2模板引擎艺沼,F(xiàn)lask提供的render_template函數(shù)封裝了該模板引擎,render_template函數(shù)的第一個(gè)參數(shù)是模板的文件名蕴掏,后面的參數(shù)都是鍵值對(duì)障般,表示模板中變量對(duì)應(yīng)的真實(shí)值

7.Web表單

web表單是web應(yīng)用程序的基本功能

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n207" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">pip3 install Flask-WTF</pre>

WTForms支持的HTML標(biāo)準(zhǔn)字段

字段對(duì)象 說明
StringField 文本字段
TextAreaField 多行文本字段
PasswordField 密碼文本字段
HiddenField 隱藏文本字段
DateField 文本字段,值為datetime.date格式
DateTimeField 文本字段盛杰,值為datetime.datetime格式
IntegerField 文本字段挽荡,值為整數(shù)
DecimalField 文本字段,值為decimal.Decimal
FloatField 文本字段饶唤,值為浮點(diǎn)數(shù)
BooleanField 復(fù)選框徐伐,值為True和False
RadioField 一組單選框
SelectField 下拉列表
SelectMultipleField 下拉列表,可選擇多個(gè)值
FileField 文本上傳字段
SubmitField 表單提交按鈕
FormField 把表單作為字段嵌入另一個(gè)表單
FieldList 一組指定類型的字段

8.數(shù)據(jù)庫

flask-sqlalchemy是一個(gè)簡(jiǎn)化了SQLAlchemy操作的flflask擴(kuò)展募狂。

1.安裝服務(wù)端

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n267" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">sudo apt-get install mysql-server</pre>

2.安裝客戶端

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n269" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev</pre>

3.數(shù)據(jù)庫的基本命令

登錄數(shù)據(jù)庫

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n272" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">mysql -u root -p</pre>

創(chuàng)建數(shù)據(jù)庫办素,設(shè)定編碼

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="sql" cid="n274" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">create database <數(shù)據(jù)庫名> charset=utf8;</pre>

顯示所有數(shù)據(jù)庫

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="sql" cid="n276" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">show databases;</pre>

在Flask中使用mysql數(shù)據(jù)庫,需要安裝一個(gè)flask-sqlalchemy的擴(kuò)展

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n278" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">pip install flask-sqlachemy</pre>

4.對(duì)比Django和Flask數(shù)據(jù)庫設(shè)置

Django :

DATABASES = { 'default': { 'ENGINE': None, # 把默認(rèn)的數(shù)據(jù)庫連接至為None } }

Flask:

app.confifig['SQLALCHEMY_DATABASE_URI'] ="************"

5.數(shù)據(jù)庫遷移

創(chuàng)建遷移倉庫

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n286" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">python database.py db init</pre>

創(chuàng)建遷移腳本

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n288" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#創(chuàng)建自動(dòng)遷移腳本
python database.py db migrate -m 'initial migration'</pre>

更新數(shù)據(jù)庫

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n290" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">python database.py db upgrade</pre>

回退數(shù)據(jù)庫

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="shell" cid="n292" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">python database.py db downgrade 版本號(hào)</pre>

9.藍(lán)圖

藍(lán)圖就是一個(gè)存儲(chǔ)操作路由映射方法的容器祸穷,主要用來實(shí)現(xiàn)客戶端請(qǐng)求和URL相互關(guān)聯(lián)的功能性穿。 在Flask中,使用藍(lán)圖可以幫助我們實(shí)現(xiàn)模塊化應(yīng)用的功能雷滚。

1.創(chuàng)建藍(lán)圖對(duì)象

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n296" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#Blueprint必須指定兩個(gè)參數(shù)需曾,admin表示藍(lán)圖的名稱,name表示藍(lán)圖 所在模塊
admin = Blueprint('admin',name)</pre>

2.注冊(cè)藍(lán)圖路由

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n298" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@admin.route('/')
def admin_index():
return 'admin_index'</pre>

3.在程序?qū)嵗?cè)路由

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n300" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">app.register_blueprint(admin,url_prefix='/admin')</pre>

實(shí)例:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="python" cid="n302" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">from flask_restful import Api
api = Api()
def init_api(app): # 傳進(jìn)來的app要繼承過數(shù)據(jù)庫配置DbConfig
api.init_app(app)

api.add_resource(class, "")</pre>

10.單元測(cè)試

常用斷言方法

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="" cid="n305" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">assertEqual 如果兩個(gè)值相等,則pass
assertNotEqual 如果兩個(gè)值不相等呆万,則pass
assertTrue 判斷bool值為True商源,則pass
assertFalse 判斷bool值為False,則pass
assertIsNone 不存在谋减,則pass assertIsNotNone 存在牡彻,則pass</pre>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市出爹,隨后出現(xiàn)的幾起案子庄吼,更是在濱河造成了極大的恐慌,老刑警劉巖严就,帶你破解...
    沈念sama閱讀 212,454評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件总寻,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡梢为,警方通過查閱死者的電腦和手機(jī)渐行,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來铸董,“玉大人殊轴,你說我怎么就攤上這事√宦” “怎么了旁理?”我有些...
    開封第一講書人閱讀 157,921評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)我磁。 經(jīng)常有香客問我孽文,道長(zhǎng),這世上最難降的妖魔是什么夺艰? 我笑而不...
    開封第一講書人閱讀 56,648評(píng)論 1 284
  • 正文 為了忘掉前任芋哭,我火速辦了婚禮,結(jié)果婚禮上郁副,老公的妹妹穿的比我還像新娘减牺。我一直安慰自己,他們只是感情好存谎,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評(píng)論 6 386
  • 文/花漫 我一把揭開白布拔疚。 她就那樣靜靜地躺著,像睡著了一般既荚。 火紅的嫁衣襯著肌膚如雪稚失。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,950評(píng)論 1 291
  • 那天恰聘,我揣著相機(jī)與錄音句各,去河邊找鬼吸占。 笑死,一個(gè)胖子當(dāng)著我的面吹牛凿宾,可吹牛的內(nèi)容都是我干的矾屯。 我是一名探鬼主播,決...
    沈念sama閱讀 39,090評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼初厚,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼问拘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起惧所,我...
    開封第一講書人閱讀 37,817評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎绪杏,沒想到半個(gè)月后下愈,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,275評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蕾久,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評(píng)論 2 327
  • 正文 我和宋清朗相戀三年势似,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片僧著。...
    茶點(diǎn)故事閱讀 38,724評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡履因,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出盹愚,到底是詐尸還是另有隱情栅迄,我是刑警寧澤,帶...
    沈念sama閱讀 34,409評(píng)論 4 333
  • 正文 年R本政府宣布皆怕,位于F島的核電站毅舆,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏愈腾。R本人自食惡果不足惜憋活,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評(píng)論 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望虱黄。 院中可真熱鬧悦即,春花似錦、人聲如沸橱乱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽泳叠。三九已至冗美,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間析二,已是汗流浹背粉洼。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工节预, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人属韧。 一個(gè)月前我還...
    沈念sama閱讀 46,503評(píng)論 2 361
  • 正文 我出身青樓安拟,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親宵喂。 傳聞我的和親對(duì)象是個(gè)殘疾皇子糠赦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容