From 8ed0597816d8cee5d83f2085eab3b0d23eedf231 Mon Sep 17 00:00:00 2001 From: liukai234 <2679327337@qq.com> Date: Sat, 30 May 2020 08:45:20 +0800 Subject: [PATCH] init template --- python_web/flasky/README.md | 9 +++++---- python_web/flasky/return.py | 30 ++++++++++++++++++++++++++++++ python_web/flasky/template.py | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 python_web/flasky/template.py diff --git a/python_web/flasky/README.md b/python_web/flasky/README.md index 5fc0119..a083b96 100644 --- a/python_web/flasky/README.md +++ b/python_web/flasky/README.md @@ -1,8 +1,9 @@ -# pip国内镜像源 +# 参考书籍:《Flask Web开发:基于Python的Web应用开发环境(第2版)》 +## pip国内镜像源 - -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -# 创建虚拟环境 +## 创建虚拟环境 - python -m venv venv-virtual-name -# 激活虚拟环境 +## 激活虚拟环境 - source venv/bin/activate -# 退出虚拟环境 +## 退出虚拟环境 - deactivate \ No newline at end of file diff --git a/python_web/flasky/return.py b/python_web/flasky/return.py index e69de29..b325bae 100644 --- a/python_web/flasky/return.py +++ b/python_web/flasky/return.py @@ -0,0 +1,30 @@ +from flask import Flask +from flask import request +from flask import make_response +from flask import redirect +from flask import abort + +app=Flask(__name__) + +@app.route('/') +def index(): + # HTTP响应状态码 200成功处理 400请求无效 + # return '

Bad Request

', 400 + + # 视图函数返回响应对象 + # response = make_response('

This document carries a cookie!

') + # response.set_cookie('answer', '42') + # return response + + # 重定向 + return redirect('http://liukai234.cn/') + +@app.route('/user/') +def get_user(id): + user = False # 判断是否为假 + if not user: + abort(404) + return '

Hello, {}

'.format(user.name) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=19722, debug=True) diff --git a/python_web/flasky/template.py b/python_web/flasky/template.py new file mode 100644 index 0000000..ba292cf --- /dev/null +++ b/python_web/flasky/template.py @@ -0,0 +1 @@ +# flask extenion \ No newline at end of file