forked from liukai234/python_course_record
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liukai234
committed
May 30, 2020
1 parent
0d889fb
commit 8ed0597
Showing
3 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# flask extenion |