目录
前言
启动文件
#app.py
from flask import Flask
from apps import create_app
app = create_app()
if __name__ == '__main__':
app.run(
把APP拿出来
# -*- codeing = utf-8 -*-
# @Time : 2021/8/25 16:05
# @Author : 二帆
# @File : __init__.py.py
# @Software : PyCharm
from flask import Flask
import settings
def create_app():
app =Flask(__name__) #app是一个核心对象
app.config.from_object(settings) #加载配置
return app
蓝图
之间的搭建关系1
之间的搭建关系2
代码
app.py
from flask import Flask
from apps import create_app
app = create_app()
if __name__ == '__main__':
app.run()
apps----->init.py
# -*- codeing = utf-8 -*-
# @Time : 2021/8/25 16:05
# @Author : 二帆
# @File : __init__.py.py
# @Software : PyCharm
from flask import Flask
import settings
from apps.users.view import user_bp
def create_app():
app =Flask(__name__,template_folder='../templates',static_folder='../static') #app是一个核心对象
app.config.from_object(settings) #加载配置
#蓝图
app.register_blueprint(user_bp)
print(app.url_map)
return app
apps----->users----->view.py
# -*- codeing = utf-8 -*-
# @Time : 2021/8/25 16:24
# @Author : 二帆
# @File : view.py
# @Software : PyCharm
from flask import Blueprint, request, render_template
user_bp = Blueprint('user',__name__)
#列表保存的是一个一个的用户对象
users = []
@user_bp.route('/')
def user_center():
if request.method == 'POST':
pass
return render_template('users/register.html')
@user_bp.route('/register',methods =['GET','POST'])
def register():
return '用户注册'
@user_bp.route('/login',methods =['GET','POST'])
def login():
return '用户登录'
@user_bp.route('/logout',methods =['GET','POST'])
def logout():
return '用户退出'
apps----->users----->model.py
# -*- codeing = utf-8 -*-
# @Time : 2021/8/25 16:54
# @Author : 二帆
# @File : model.py
# @Software : PyCharm
class User:
def __init__(self,username,password,phone=None):
self.username = username
self.password = password
self.phone = phone
def __str__(self):
return self.username
templates----->base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title%}用户中心{% endblock %}</title>
<style>
#head{
height:50px;
background-color: bisque;
}
#head ul{
list-style: none;
}
#head ul li{
float: left;
width:100px;
text-align: center;
font-size:18px;
height:50px;
line-height: 50px;
}
#middle{
height: 600px;
}
#foot{
height: 50px;
line-height: 50px;
background-color: darkcyan;
}
</style>
{% block mycss %}{% endblock %}
</head>
<body>
<div id="head">
<ul>
<li><a href="">首页</a></li>
<li><a href="">秒杀</a></li>
<li><a href="">秒杀</a></li>
<li><a href="">会员</a></li>
<li><a href="">图书</a></li>
</ul>
</div>
<div id="middle">
{% block middle %}
{% endblock %}
</div>
<div id="footer"></div>
{% block myjs %}{% endblock %}
</body>
</html>
templates------>users-------->register.html
{% extends 'base.html' %}
{% block title %}
用户注册
{% endblock %}
{% block middle %}
<form action="/register" method="post">
<p><input type="text" name="username" placeholder="用户名"></p>
<p><input type="password" name="password" placeholder="密码"></p>
<p><input type="password" name="repassword" placeholder="确认密码"></p>
<p><input type="number" name="phone" placeholder="手机号码"></p>
<p><input type="submit" value="用户注册"></p>
</form>
{% endblock %}