lor*_*tar 0 html python jinja2 flask
我有一个简单的 HTML 模板,如下所示:
<html>
<head> Sentiment Analysis Dataset</head>
<form method='POST'>
<b> Unclassified Text </b>
<input type='text' name='Text' value={{db.Entry}} readonly><br>
</form>
</html>
Run Code Online (Sandbox Code Playgroud)
以下是我的 Flask 代码:
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
db={'Entry':data.next()}
print db
return render_template('index.html', db=db)
elif request.method == 'POST':
db={'Entry':data.next()}
print db
return render_template('index.html', db=db)
Run Code Online (Sandbox Code Playgroud)
db 字典看起来像{'Entry': 'Worst thing I've ever seen'}. 当我运行应用程序时,它只显示 html 文本框中的第一个单词。为什么会出现这种情况?我该怎么做才能在文本框中显示整个字符串?
编辑:我刚刚将 {{db.Entry}} 用引号引起来,它起作用了
小智 8
我不知道 Flask,但是,如果你在 html 输入的值两边加引号会发生什么?
例如
<input type='text' name='Text' value='{{db.Entry}}' readonly><br>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1638 次 |
| 最近记录: |