如何在接受輸入時(shí)刪除 HTML 表單顯示的 (b' & \n),將其發(fā)送到 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 已成功添加到數(shù)據(jù)庫...\n'
1 回答

慕姐4208626
TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
假設(shè)您的消息存儲在變量中:
your_message = b'xxx Added Successfully To Database...\n' formatted_message = your_message.replace(b'\n', b'')
然后輸出formatted_message。當(dāng)在 html 中使用
標(biāo)簽時(shí),我會對向用戶顯示的所有消息進(jìn)行這樣的替換。
編輯:如果要將字節(jié)對象轉(zhuǎn)換為普通字符串,可以執(zhí)行以下操作:
formatted_message = formatted_message.decode()
- 1 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)
0/150
提交
取消