统一 UTF-8 编码,中文支持。 前端使用 HTML(尽量兼容老旧浏览器(NetSurf)且不使用JS)。 服务端使用 python(尽量不引入第三方库),搭建最小轻量化独立聊天室。慢慢来,实现以下功能:
地址:(/)
用户界面:
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<title>聊天室</title>
<link type="text/css" rel="stylesheet" href="html-chat.css">
<meta name="viewport" content="width=192, initial-scale=1.0">
</head>
<body>
<div class="container">
<form action="/chat" method="get">
<fieldset>
<legend>主页</legend>
<label for="nickname">昵称</label>
<input type="text" id="nickname" name="nickname" value="匿名">
<br>
<label for="roomid">房间号:</label>
<input type="text" id="roomid" name="roomid" value="默认">
<br>
<button type="submit">进入聊天室</button>
</fieldset>
</form>
</div>
</body>
</html>
地址:(/chat?nickname=昵称&roomid=聊天室号码)
用户界面:
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<title>聊天室 - {roomid}</title>
<link type="text/css" rel="stylesheet" href="html-chat.css">
<meta name="viewport" content="width=192, initial-scale=1.0">
</head>
<body>
<div class="container">
<form action="./send_message" method="post">
<fieldset>
<legend>聊天室 - {roomid}</legend>
<iframe src="./log?id={roomid}" frameborder="0">加载中……</iframe>
<br>
<label for="messageInput">{nickname}说:</label>
<input type="text" id="messageInput" name="messageInput">
<button type="submit">发送</button>
<a href=".">退出</a>
</fieldset>
<input type="text" id="nickname" name="nickname" value="{nickname}" style="display: none;">
<input type="text" id="roomid" name="roomid" value="{roomid}" style="display: none;">
</form>
</div>
</body>
</html>
302 重定向回聊天室。
配置读写:
HTTP请求处理:
聊天室管理:
用户交互:
安全与启动:
命令行参数: