Skip to content

Commit

Permalink
init template
Browse files Browse the repository at this point in the history
  • Loading branch information
liukai234 committed May 30, 2020
1 parent 0d889fb commit 8ed0597
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python_web/flasky/README.md
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions python_web/flasky/return.py
Original file line number Diff line number Diff line change
@@ -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 '<h1>Bad Request</h1>', 400

# 视图函数返回响应对象
# response = make_response('<h1>This document carries a cookie!</h1>')
# response.set_cookie('answer', '42')
# return response

# 重定向
return redirect('http://liukai234.cn/')

@app.route('/user/<id>')
def get_user(id):
user = False # 判断是否为假
if not user:
abort(404)
return '<h1>Hello, {}</h1>'.format(user.name)

if __name__ == "__main__":
app.run(host="0.0.0.0", port=19722, debug=True)
1 change: 1 addition & 0 deletions python_web/flasky/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# flask extenion

0 comments on commit 8ed0597

Please sign in to comment.