gpt4 book ai didi

python - 仅当部署在 GAE 上时,html textarea 提交才会导致 '=' 字符在新行中显示

转载 作者:太空宇宙 更新时间:2023-11-03 19:16:11 26 4
gpt4 key购买 nike

当我在 http://localhost:8080 上的 Windows GAE 启动器的文本区域框中提交以下文本时,它显示正常。

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a dolor eget diam
condimentum varius. Proin malesuada dictum ante, sed commodo purus vestibulum in.
Sed nibh dui, volutpat eu porta eu, molestie ut lacus. Vivamus iaculis urna ut tellus
blandit eu at nisl. Fusce eros libero, aliquam vitae hendrerit vitae, posuere ac diam.
Vivamus sagittis, felis in imperdiet pellentesque, eros nibh porttitor nisi, id
tristique leo libero a ligula. In in elit et velit auctor lacinia eleifend cursus mauris. Mauris
pellentesque lorem et augue placerat ultrices. Nam sed quam nisl, eget elementum felis.
Integer sapien ipsum, aliquet quis viverra quis, adipiscing eget sapien. Nam consequat
lacinia enim, id viverra nisl molestie feugiat.

当我点击提交按钮后将我的代码部署到 GAE 上时,它会显示如下:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a dolor eg=
et diam condimentum varius. Proin malesuada dictum ante, sed commodo purus =
vestibulum in. Sed nibh dui, volutpat eu porta eu, molestie ut lacus. Vivam=
us iaculis urna ut tellus tempor blandit eu at nisl. Fusce eros libero, ali=
quam vitae hendrerit vitae, posuere ac diam. Vivamus sagittis, felis in imp=
erdiet pellentesque, eros nibh porttitor nisi, id tristique leo libero a li=
gula. In in elit et velit auctor lacinia eleifend cursus mauris. Mauris pel=
lentesque lorem et augue placerat ultrices. Nam sed quam nisl, eget element=
um felis. Integer sapien ipsum, aliquet quis viverra quis, adipiscing eget =
sapien. Nam consequat lacinia enim, id viverra nisl molestie feugiat.

实现说明如下:

我正在使用 jinja2 引擎。我有 autescape = false:

jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = False)

我从文本区域元素获取内容。以下是它在我的模板中的设置方式:

  <label>
<div>Information</div>
<textarea name="information">{{r.information}}</textarea>
</label>

我使用以下方法检索字符串:

information = self.request.get('information')

我将字符串提交到数据存储

r.information = information
r.put()

再次显示它进行编辑时,我使用相同的模板代码:

  <label>
<div>Information</div>
<textarea name="information">{{r.information}}</textarea>
</label>

本地一切都运行良好。但是当我将它部署到谷歌应用程序引擎时,我得到了一些奇怪的结果。我想知道这些 = 符号是从哪里来的?

编辑:
为了澄清起见,它在每行末尾放置了=CRLF。

*编辑 2:*以下是该 bug 的注释 21 中的代码:

def from_fieldstorage(cls, fs):
"""
Create a dict from a cgi.FieldStorage instance
"""
obj = cls()
if fs.list:
# fs.list can be None when there's nothing to parse
for field in fs.list:
if field.filename:
obj.add(field.name, field)
else:

# first, set a common charset to utf-8.
common_charset = 'utf-8'

# second, check Content-Transfer-Encoding and decode
# the value appropriately
field_value = field.value
transfer_encoding = field.headers.get(
'Content-Transfer-Encoding', None)

if transfer_encoding == 'base64':
field_value = base64.b64decode(field_value)

if transfer_encoding == 'quoted-printable':
field_value = quopri.decodestring(field_value)

if field.type_options.has_key('charset') and \
field.type_options['charset'] != common_charset:
# decode with a charset specified in each
# multipart, and then encode it again with a
# charset specified in top level FieldStorage
field_value = field_value.decode(
field.type_options['charset']).encode(common_charset)

# TODO: Should we take care of field.name here?
obj.add(field.name, field_value)

return obj

multidict.MultiDict.from_fieldstorage = classmethod(from_fieldstorage)

最佳答案

您可能违反了 this bug评论 21 中的解决方法过去对我有用,最近的评论表明它仍然有效。

关于python - 仅当部署在 GAE 上时,html textarea 提交才会导致 '=' 字符在新行中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com