赞
踩
本文章摘自本人的毕业设计的论文(已毕业),主要作为存储的目的,怕那天电脑坏了。可以模仿,不能抄袭。
代码 1 模型参数训练及误差计算代码
代码 2 模型训练及sbt文件
代码 3 注册功能逻辑函数
def m_register():
if request.method == ‘GET’:
return render_template(“register.html”)
else:
form = RegisterForm(request.form)
if form.validate():
email = form.email.data
Userid = form.Userid.data
# 对存储在数据库中的密码进行加密
password = form.password.data
hash_password = generate_password_hash(password)
NU = NewUserModel(Userid=Userid,email=email, password=hash_password)
db.session.add(NU)
db.session.commit()
return redirect(url_for(“user.login”)) # 重定向到/user/login路由,让用户登录
else:
return redirect(url_for(“user.register”))
代码 4 发送验证码功能代码
app.config.update( # 发送邮箱验证码功能
MAIL_SERVER=‘smtp.163.com’, #选择163服务器
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME=‘183********@163.com’, #负责发送的邮箱
MAIL_PASSWORD=‘HAOOEVQTSUDCYVYT’)
mail = Mail(app)
@app.route(‘/user/captcha’,methods=[‘POST’])
def get_captcha():
email = request.form.get(“email”)
# 邮箱验证码设定为4位字符
letters = string.ascii_letters+string.digits
captcha = “”.join(random.sample(letters, 4))
if email:
# Message(主题,发件人,收件人)
msg = Message(“你好,欢迎体验”, sender=“18301169790@163.com”, recipients=[email])
msg.body = f"你的验证码是:{captcha}。"
mail.send(msg)
# 查询MYSQL 看是否有该email已经注册过
captcha_model = EmailCaptchModel.query.filter_by(email=email).first()
if captcha_model:
captcha_model.captcha = captcha #如果之前存在验证码,进行更新
captcha_model.create_time = datetime.now() # 更新发送时间
db.session.commit()
else: # 如果没有该email即是第一次注册,就增加数据
captcha_model = EmailCaptchModel(email=email, captcha=captcha)
db.session.add(captcha_model)
db.session.commit()
print(“验证码:”, captcha)
# code: 200 表示成功的、正常的请求
return jsonify({“code”: 200})
else:
return jsonify({“code”: 400, “message”: “请先传递邮箱!”}) # 400客户端错误
代码 5 发送按钮功能函数
index.css
/模板中可以加载css静态文件以丰富界面,可以更改h1和h2的字体等/
h1{
color: #bd2130;
font-weight:bold
}
.comment-ul li{
padding: 10px;
overflow: hidden;
display: flex;
background-color: #fff;
border-bottom:1px solid #eee;
}
.side-comment{
flex-basis: 38px;
height:100%;
}
.side-comment-avatar{
width: 40px;
height:40px;
border-radius: 3px;
}
.comment-main{
flex: 1;
width: 660px;
height: 100px;
margin-left:10px;
overflow: hidden;
}
.comment-title a{
color:#c82333;
font-size:16px;
font-weight: 900;
}
.comment-author{
font-size: 14px;
margin-top: 5px;
}
.comment-content{
margin-top: 5px;
font-size:14px;
}
.comment-detail{
text-align: right;
margin-top: 10px;
}
.comment-detail .comment-author{
margin-right:10px;
}
detail.css
.page-title{
text-align: center;
}
.comment-info{
text-align: right;
}
.comment-group-title{
margin-top: 20px;
}
.form-container{
width: 500px;
margin-top: 10px;
text-align: right;
}
.comment-group{
list-style: none;
padding-left: 0;
}
.comment-group li{
border-bottom:1px solid #eee;
padding: 10px 0;
}
.comment-group li .user-info{
height: 40px;
line-height:40px;
color: #9b9b9b;
font-size: 16px;
}
.user-info .avatar{
height:40px;
width: 40px;
float: left;
border-radius: 50%;
}
.user-info .username{
margin-left: 10px;
}
.user-info .create-time{
float: right;
}
.comment-content{
margin-left: 50px;
}
base.html
*
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{% block title %}{% endblock %}</title> <link rel="stylesheet" href="{{ url_for('static',filename='bootstrap/bootstrap.4.6.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static',filename='css/init.css') }}"> {% block head %}{% endblock %} </head> {#nav导航条#} <body> <nav class="navbar navbar-expand-lg navbar-default bg-dark"> <div class="container"> <a class="navbar-brand" href="#">模拟音乐推荐系统</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="/">首页<span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('comment.public_question') }}">留言</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('hot_music.hot_music') }}">热门歌手200</a> </li> <li class="nav-item ml-5"> <form class="form-inline my-lg-0 mx-5" method="get" action="{{ url_for('rmd.rmd_show') }}"> <input class="form-control mr-sm-3" type="search" placeholder="个性化推荐:输入userid" name="q" aria-label="Search"> <button class="btn btn-danger my-5 my-sm-n1" type="submit">推荐</button> </form> </li> </ul> <ul class="navbar-nav "> {% if user %} <li class="nav-item "> <a class="nav-link" href="#">{{ user.Userid }}</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('user.logout') }}">退出登录</a> </li> {% else %} <li class="nav-item "> <a class="nav-link" href="{{ url_for('user.login') }}">登录</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for('user.register') }}">注册</a> </li> {% endif %} </ul> </div> </div> </nav> <div class="container"> {% block body %} {% endblock %} </div> </body> </html>
index.html
{% extends "base.html" %} {% block title %}系统首页{% endblock %} {% block head %} <link rel="stylesheet" href="{{ url_for('static',filename='css/index.css') }}"> <style> body { background-image: url("/static/images/1.jpg"); } </style> {% endblock %} {% block body %} <div class="row" style="margin-top: 20px;"> <div class="col"></div> <div class="col-10"> <ul class="comment-ul"> {% for s in ss %} <li> <div class="side-comment"> <img class="side-comment-avatar" src="{{ url_for('static',filename='images/messi.jpg') }}" alt=""> </div> <div class="comment-main"> {# 通过点击title跳转到详情界面,参数在url_for中传递#} <div class="comment-title"><a href="{{ url_for('comment.question_detail', question_id=s.id) }}">{{ s.title }}</a></div> <div class="comment-content"> {{ s.content }} </div> <div class="comment-detail"> <div class="comment-author"> 用户:{{ s.author_id }} </div> <div class="comment-time"> 时间:{{ s.create_time }} </div> </div> </div> </li> {% endfor %} </ul> </div> <div class="col"></div> </div> {% endblock %}
比较简陋,就这水平,勿喷 (1838****32@qq.com)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。