flask登录注册页面模板
时间: 2024-03-30 18:31:40 浏览: 38
Flask是一个基于Python的轻量级Web应用框架,它提供了一种简单而灵活的方式来构建Web应用程序。在Flask中,可以使用模板引擎来渲染动态内容,包括登录和注册页面。
下面是一个简单的Flask登录注册页面模板的示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
</head>
<body>
<h1>登录</h1>
<form action="/login" method="POST">
<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>
<h1>注册</h1>
<form action="/register" method="POST">
<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表单来实现登录和注册功能。用户可以输入用户名和密码,并通过提交表单来进行登录或注册操作。表单的`action`属性指定了提交表单时要发送请求的URL,`method`属性指定了请求的HTTP方法(POST)。
你可以将上述代码保存为一个名为`login.html`的文件,并在Flask应用程序中使用`render_template`函数来渲染该模板:
```python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('login.html')
if __name__ == '__main__':
app.run()
```
在上述代码中,我们定义了一个Flask应用程序,并创建了一个路由`/`,当用户访问根路径时,会渲染`login.html`模板并返回给用户。