【发布时间】:2018-07-26 06:21:25
【问题描述】:
我正在使用烧瓶来显示基于系统中静态文件的 wordcloud。页面加载后,我希望用户能够输入停用词以便能够在提交时更新词云。使用当前代码,当用户提交新的停用词时,stop_words 列表会更新,但当模板再次呈现时,它不会更新词云。 get_nmf_topics(model, 20) 使用主题生成器 (nmf) 创建单词和权重列表,并在该函数中处理 stop_words。
@app.route('/')
def home_page():
return render_template('index.html')
@app.route('/word_cloud', methods=['GET'])
def word_cloud():
try:
words=get_nmf_topics(model, 20)
# JQCloud requires words in format {'text': 'sample',
'weight':'100'}
# so, lets convert out word_freq in the respective format
words_json = [{'text': word, 'weight': weight} for word, weight in
words]
# now convert it into a string format and return it
#return json.dumps(words_json)
return json.dumps(words_json)
except Exception as e:
return '[]'
@app.route('/', methods=['POST'])
def parse_data():
text = request.form['text']
stop_words.append(text)
print(stop_words)
return redirect(url_for('parse_data'))
【问题讨论】:
标签: python forms flask textinput