一.搭建会员登录模块
1.在views.py
文件中引入redirect
和url_for
方法
from flask import render_template,redirect,url_for
2.定义登录模块的路由和映射
@home.route("/login/")
def login():
return render_template("home/login.html")
@home.route("/logout/")
def logout():
return redirect(url_for("home.login"))
3.定义登录模板
(1) 在D:\Python学习\movie\app\templates\home
文件夹下新建login.html
登录模板.
(2) copyD:\Python学习\movie\app\static\tpl\2-movie
文件夹下的login.html
中的内容部分到D:\Python学习\movie\app\templates\home
文件夹下的login.html
中.
{% extends "home/home.html" %}
{% block content %}
<!--内容-->
<div class="container" style="margin-top:120px">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-log-in"></span> 会员登录</h3>
</div>
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">
<label for="input_contact"><span class="glyphicon glyphicon-user"></span> 账号</label>
<input id="input_contact" class="form-control input-lg" placeholder="用户名/邮箱/手机号码" name="contact" type="text" autofocus>
</div>
<div class="col-md-12" id="error_contact"></div>
<div class="form-group">
<label for="input_password"><span class="glyphicon glyphicon-lock"></span> 密码</label>
<input id="input_password" class="form-control input-lg" placeholder="密码" name="password" type="password" value="">
</div>
<div class="col-md-12" id="error_password"></div>
<a href="user.html" class="btn btn-lg btn-success btn-block">登录</a>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<!--内容-->
{% endblock %}
4.在index.html
中设置登录和退出的导航
<a class="curlink" href="{{ url_for('home.login') }}"><span class="glyphicon glyphicon-log-in"></span> 登录</a>
<a class="curlink" href="{{ url_for('home.logout') }}"><span class="glyphicon glyphicon-log-out"></span> 退出</a>
二.搭建会员注册模块
1.定义注册模块的路由和映射
@home.route("/register/")
def register():
return render_template("home/register.html")
2.copyD:\Python学习\movie\app\static\tpl\2-movie
文件夹下的register.html
中的内容部分到D:\Python学习\movie\app\templates\home
文件夹下的register.html
中.
{% extends "home/home.html"%}
{% block content %}
<!--内容-->
<div class="container" style="margin-top:120px">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-plus"></span> 会员注册</h3>
</div>
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">
<label for="input_name"><span class="glyphicon glyphicon-user"></span> 昵称</label>
<input id="input_name" class="form-control input-lg" placeholder="昵称" name="name" type="text" autofocus>
</div>
<div class="col-md-12" id="error_name"></div>
<div class="form-group">
<label for="input_email"><span class="glyphicon glyphicon-envelope"></span> 邮箱</label>
<input id="input_email" class="form-control input-lg" placeholder="邮箱" name="email" type="email" autofocus>
</div>
<div class="col-md-12" id="error_email"></div>
<div class="form-group">
<label for="input_phone"><span class="glyphicon glyphicon-phone"></span> 手机</label>
<input id="input_phone" class="form-control input-lg" placeholder="手机" name="phone" type="text" autofocus>
</div>
<div class="col-md-12" id="error_phone"></div>
<div class="form-group">
<label for="input_password"><span class="glyphicon glyphicon-lock"></span> 密码</label>
<input id="input_password" class="form-control input-lg" placeholder="密码" name="password" type="password" value="">
</div>
<div class="col-md-12" id="error_password"></div>
<div class="form-group">
<label for="input_repassword"><span class="glyphicon glyphicon-lock"></span> 确认密码</label>
<input id="input_repassword" class="form-control input-lg" placeholder="确认密码" name="repassword" type="password" value="">
</div>
<div class="col-md-12" id="error_repassword"></div>
<a href="user.html" class="btn btn-lg btn-success btn-block">注册</a>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<!--内容-->
{% endblock %}
3.在index.html
中设置注册的导航
<a class="curlink" href="{{ url_for('home.register') }}"><span class="glyphicon glyphicon-plus"></span> 注册</a>
三.搭建会员中心模块
1.定义会员模块的路由和映射
@home.route("/user/")
def user():
return render_template("home/user.html")
@home.route("/pwd/")
def pwd():
return render_template("home/pwd.html")
@home.route("/comments/")
def comments():
return render_template("home/comments.html")
@home.route("/loginlog/")
def loginlog():
return render_template("home/loginlog.html")
@home.route("/moviecol/")
def moviecol():
return render_template("home/moviecol.html")
2.引入前台模板
3.分离出菜单栏,并修改url
<div class="col-md-3">
<div class="list-group">
<a id="m-1" href="{{ url_for('home.user') }}" class="list-group-item">
<span class="glyphicon glyphicon-user"></span> 会员中心
</a>
<a id="m-2" href="{{ url_for('home.pwd') }}" class="list-group-item">
<span class="glyphicon glyphicon-lock"></span> 修改密码
</a>
<a id="m-3" href="{{ url_for('home.comments') }}" class="list-group-item">
<span class="glyphicon glyphicon-comment"></span> 评论记录
</a>
<a id="m-4" href="{{ url_for('home.loginlog') }}" class="list-group-item">
<span class="glyphicon glyphicon-calendar"></span> 登录日志
</a>
<a id="m-5" href="{{ url_for('home.moviecol') }}" class="list-group-item">
<span class="glyphicon glyphicon-heart"></span> 收藏电影
</a>
</div>
</div>