站点结构
入口类 : flask类的实例、@app.route('/')路由装饰响应处理函数、程序配置 app.debug=True、程序运行
site->static(images、js、css)、templates(index.html)


请求/响应流程
路由接收请求
分配请求给特定的视图函数
视图函数返回视图
mvc流程示例

1、简单的vc模式
@app.route('/')
def index():
return render_template('index.html')
hello.py文件

body{
font-size: 16;
color: #333;
}
h1,h2,h3{
font-weight: 300;
}
style.css文件
2、mvc结构
class Book:
def __init__(self, title, price, author, publisher):
self.title = title
self.price = price
self.author = author
self.publisher = publisher
def __str__(self):
return '<Book {}>'.format(self.title)
book.py文件
@app.route('/books/')
def book_list():
books = [
Book('python flask', 59.00, 'dong', '人民邮电出版社'),
Book('python selenium', 59.00, 'dong', '人民邮电出版社'),
Book('python 爬虫', 59.00, 'dong', '人民邮电出版社'),
Book('python 多线程', 59.00, 'dong', '人民邮电出版社'),
Book('python 语言', 59.00, 'dong', '人民邮电出版社')
]
return render_template('book-list.html', books=books)
hello.py文件

今天是一个整体的示例,后面将会有对各个部分的讲解,大家了解整体的流程就可以了。后面的开发也都会大体遵循这种流程模式的。
网友评论