利用python和SqlServer和html创建一个学生登入页面,并给出简单代码
时间: 2024-05-09 14:19:02 浏览: 9
以下是一个简单的学生登入页面的Python代码:
```python
import pyodbc
# 连接到SQL Server数据库
conn_str = (
"DRIVER={SQL Server};"
"SERVER=myServerName;"
"DATABASE=myDatabaseName;"
"UID=myUsername;"
"PWD=myPassword;"
)
cnxn = pyodbc.connect(conn_str)
# 获取学生信息
cursor = cnxn.cursor()
cursor.execute("SELECT * FROM Students")
students = cursor.fetchall()
# 创建HTML页面
html = """
<!DOCTYPE html>
<html>
<head>
<title>学生登入</title>
</head>
<body>
<h1>学生登入</h1>
<form method="POST" action="/login">
<label for="username">用户名:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="登入">
</form>
</body>
</html>
"""
# 输出HTML页面
print(html)
```
这个代码连接到一个SQL Server数据库,获取学生信息,并创建一个简单的HTML页面,其中包含一个表单,用于学生登入。学生信息可以从数据库中获取,也可以从其他来源获取。此代码仅用于演示目的,需要根据具体需求进行修改和完善。