关于用flask+flask_whooshalchemyplus全文检索问题
最近学校老师让我们自己学习搜索引擎用python语言的,自己网上查了很多,但还是有问题。如下程序代码:
__init__.py from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) # 配置 sqlalchemy 数据库驱动://数据库用户名:密码@主机地址:端口/数据库?编码 app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@localhost:3306/BYSJ?charset=utf8' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['WHOOSH_BASE'] = 'path/to/whoosh/base' # 初始化 db = SQLAlchemy(app) models.py from jieba.analyse.analyzer import ChineseAnalyzer import flask_whooshalchemyplus from __init__ import db, app class filemessage(db.Model): __tablename__ = 'filemessage' __searchable__ = ['title', 'content'] __analyzer__ = ChineseAnalyzer() id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Unicode) content = db.Column(db.Text) flask_whooshalchemyplus.init_app(app) view.py from flask import render_template, request from flask_bootstrap import Bootstrap from flask_whooshalchemyplus import index_all from __init__ import * from models import filemessage app = Flask(__name__) bootstrap = Bootstrap(app) @app.route('/') def home(): index_all(app) return render_template('search_results.html') @app.route('/search', methods=['GET']) def search_results(): query = request.args.get('search') results = filemessage.query.whoosh_search(query).all() return render_template('search_results.html', results=results) if __name__ == '__main__': app.debug = True app.run() #前端 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <form action="{{url_for('search')}}" method="get"> <input type="text" placeholder="站内搜索" name="search" > <button type="submit">搜索</button> </form> </div> <div> <ul> {% for post in results %} <li> <div> <div> {{ post.title }} {{ post.content }} </div> </div> </li> {% endfor %} </ul> </div> </body> </html>
错误如下:
拒绝访问path是什么意思,没有这个路径我记得可以自己创建的,本人刚学flask,希望知乎大佬老解读