在 python 3.4 中使用 flask 截断字符串文字
String literals are truncated using flask in python 3.4
当我 运行 以下简单的 python / flask 时,我没有将整个字符串传递到 html 页面 - 而不是 "hello this is simon" 我得到 "hello"
我正在开发 Python 3.4.2
我认为这可能与编码有关,但我已经尝试了所有我能想到的编码方法,但仍然没有任何乐趣。非常感谢收到的任何帮助:)
这是 python 文件 (testit.py)
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def init_logon():
email = "hello this is simon"
return render_template("testit.html", email=email)
if __name__ == '__main__':
app.debug = True
app.run()
这是简单模板(testit.html)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>
<label for="email">Email</label>
<input type="text" name="email" id="email" value={{ email }}>
</p>
</body>
</html>
许多浏览器的输出都是一样的:文本是 t运行第一个白色 space
我的浏览器显示的是:
"hello" - 第一个白色space通过后的文字none
抱歉我不能 post 我创建的图像 :(
在你的 HTML 中,你没有引用属性值,所以你的模板的结果是
<input type="text" name="email" id="email" value=hello this is simon>
这意味着只有 "hello" 是 "value" 属性的值。如果您查看生成页面的源代码,您应该能够看到这一点。
您可以更改模板,使其具有 value="{{ email }}"
。
当我 运行 以下简单的 python / flask 时,我没有将整个字符串传递到 html 页面 - 而不是 "hello this is simon" 我得到 "hello" 我正在开发 Python 3.4.2
我认为这可能与编码有关,但我已经尝试了所有我能想到的编码方法,但仍然没有任何乐趣。非常感谢收到的任何帮助:)
这是 python 文件 (testit.py)
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def init_logon():
email = "hello this is simon"
return render_template("testit.html", email=email)
if __name__ == '__main__':
app.debug = True
app.run()
这是简单模板(testit.html)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>
<label for="email">Email</label>
<input type="text" name="email" id="email" value={{ email }}>
</p>
</body>
</html>
许多浏览器的输出都是一样的:文本是 t运行第一个白色 space
我的浏览器显示的是:
"hello" - 第一个白色space通过后的文字none
抱歉我不能 post 我创建的图像 :(
在你的 HTML 中,你没有引用属性值,所以你的模板的结果是
<input type="text" name="email" id="email" value=hello this is simon>
这意味着只有 "hello" 是 "value" 属性的值。如果您查看生成页面的源代码,您应该能够看到这一点。
您可以更改模板,使其具有 value="{{ email }}"
。