我希望在flask的“reommendationSearch”中引入一个外部模块,它基本上是根据相似关键词的频率来计算电影标题的相似性
我的问题出现在尝试将其与flask集成时,其中“title”是“search_string”。 错误: “AttributeError:”NoneType“对象没有属性”“index”“。”。这是 回溯:
烧瓶代码:
from flask import Flask, render_template, flash, redirect, url_for, session, logging, request
from wtforms import Form,StringField, TextAreaField, PasswordField, validators
from ReccomendationTest import reommendationSearch
# Parse HTML Page via Flask
@app.route('/')
def index():
return render_template('home.html')
class searchForm(Form):
search = StringField('Movie Title:')
@app.route('/about',methods = ['GET','POST'])
def search_results():
form = searchForm(request.form)
search_string = form.search.data
search_results = reommendationSearch()
output_results = search_results.get_recommendations(search_string)
results=[]
if request.method == 'POST':
return(output_results)
if __name__ =="__main__":
app.secret_key='secret123'
app.run()
推荐试验:
^{pr2}$
您有一个未定义的
title
变量,您没有在代码中声明。在如果标题是通过'POST'请求从用户那里获得的内容,请考虑向POST查询添加一个param并将其传递到“reommendationSearch”类中。在
编辑:我刚刚注意到您使用的是wtforms,在任何情况下,标题都不会传递到“get_recommendations”函数中,因为它是类外部的,因此没有在该类的范围内定义。在
在任何情况下,解决方案都是确保在类内部定义
title
变量。在相关问题 更多 >
编程相关推荐