首先,flask项目中,已经开启csrf的保护
from flask.ext.wtf import CSRFProtect
CSRFProtect(app)
只需在表单中加入 csrf_token() 直接调用,系统会帮你自动生成 csrf_token的值
<form class="news_filter_form" method="post" >
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<input name="keywords" type="text" placeholder="请输入关键字" class="input_txt">
<input type="submit" value="搜 索" class="input_sub"
</form>