外部模块进入Flask类型错误:“Series”对象不是callab

2024-10-03 02:32:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望在flask的“reommendationSearch”中引入一个外部模块,它基本上是根据相似关键词的频率来计算电影标题的相似性

我的问题出现在尝试将其与flask集成时,其中“title”是“search_string”。 错误: “AttributeError:”NoneType“对象没有属性”“index”“。”。这是 回溯:

Traceback Snapshot

烧瓶代码:

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}$

Tags: fromimportformappflasksearchstringindex
1条回答
网友
1楼 · 发布于 2024-10-03 02:32:06

您有一个未定义的title变量,您没有在代码中声明。在

如果标题是通过'POST'请求从用户那里获得的内容,请考虑向POST查询添加一个param并将其传递到“reommendationSearch”类中。在

@app.route('/about',methods = ['GET','POST'])    
def search_results():
    req_title = request.args.get('title')
    search_results = reommendationSearch(req_title)
...

class reommendationSearch(title):
    # And here goes the rest of your code

编辑:我刚刚注意到您使用的是wtforms,在任何情况下,标题都不会传递到“get_recommendations”函数中,因为它是类外部的,因此没有在该类的范围内定义。在

在任何情况下,解决方案都是确保在类内部定义title变量。在

相关问题 更多 >