html - 在浏览器上呈现 HTML 表单接收到的数据
问题描述
如何在接受输入时删除 HTML 表单显示的 (b' & \n),将其发送到 Python 脚本并获取要显示的输出:
<p id= "in">Please Do:<br />
<br />
1) Verify the serial.<br />
2) Input the serial.<br />
<form action="input" method="post">
{% csrf_token %}
Serial Number:
<input type="text" name="param" required>
<input type="submit" value="Submit"><br />
<br />
{{data_input}}
{{data1|safe}}
<br />
<br />
</form>
</p>
显示的输出:
b'xxx 成功添加到数据库...\n'
解决方案
假设您的消息存储在一个变量中:
your_message = b'xxx Added Successfully To Database...\n'
formatted_message = your_message.replace(b'\n', b'')
然后输出formatted_message。在 html 中使用
标签时,我会在显示给用户的所有消息上进行这样的替换。
编辑:如果要将字节对象转换为普通字符串,可以执行以下操作:
formatted_message = formatted_message.decode()
推荐阅读
- javascript - 无法读取 null 的属性“addRole”
- python - Okhttp 无法连接到 localhost 端点抛出连接失败:ECONNREFUSED(连接被拒绝)
- r - 在 Rstudio/R 绘图或查看器窗口中显示/打印 huxtable;不编织降价文档?
- ruby-on-rails - 我的 Rails 模型和控制器名称会与 Rails 的保留字冲突吗?
- proxy - 旋转代理(STORM,SMART)没有在每个scrapy请求中提供唯一的IP
- typescript - 打字稿:带有剩余只读数组的参数永远不会
- javascript - useState 不适用于对象数组
- ajax - Laravel 将相同产品的添加到购物车按钮添加到购物车,数量 +1
- ruby-on-rails - parse_markdown 和截断
- python - 在 python 中提取 3D 图像补丁时出现大的分配错误