Skip to content

Commit 2b320c1

Browse files
committed
gitlab gerrit api
1 parent e7fbe3b commit 2b320c1

1,112 files changed

Lines changed: 186368 additions & 407 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmdb/cmdb.py

Whitespace-only changes.

exercise/.DS_Store

0 Bytes
Binary file not shown.

exercise/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from inspect import signature
77

88

9-
def add1(x:int, y:int, *args, **kwargs) -> int :
9+
def add1(x: int, y: int, *args, **kwargs) -> int:
1010
return x + y
1111

1212

flask/app.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
"""
2+
flask exercise
3+
"""
4+
from flask import Flask, url_for, request
5+
from flask import render_template
6+
import logging
7+
FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
8+
logging.basicConfig(level=logging.INFO)
9+
logger = logging.getLogger('flask')
10+
handler = logging.FileHandler('flask.log')
11+
fmt = logging.Formatter(FORMAT)
12+
handler.setFormatter(fmt)
13+
logger.addHandler(handler)
14+
15+
# from logging.config import dictConfig
16+
#
17+
# dictConfig({
18+
# 'version': 1,
19+
# 'formatters': {'default': {
20+
# 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
21+
# }},
22+
# 'handlers': {'wsgi': {
23+
# 'class': 'logging.StreamHandler',
24+
# 'stream': 'ext://flask.logging.wsgi_errors_stream',
25+
# 'formatter': 'default'
26+
# }},
27+
# 'root': {
28+
# 'level': 'INFO',
29+
# 'handlers': ['wsgi']
30+
# }
31+
# })
32+
33+
app = Flask(__name__)
34+
35+
36+
# 路由
37+
# @app.route('/')
38+
# def index():
39+
# return 'index'
40+
41+
42+
# @app.route('/hello')
43+
# def hello():
44+
# return 'hello world!'
45+
46+
47+
@app.route('/post/<int:post_id>')
48+
def show_post(post_id):
49+
return 'Post {}'.format(post_id)
50+
51+
52+
@app.route('/path/<path:subpath>')
53+
def show_subpath(subpath):
54+
return 'Subpath: {}'.format(subpath)
55+
56+
57+
"""
58+
转换器类型:
59+
string:缺省值,接受任何不包含斜杠的文本
60+
int:
61+
float:
62+
path:类似string,可以接受斜杠
63+
uuid:接受UUID字符串
64+
"""
65+
66+
67+
@app.route('/projects/')
68+
def projects():
69+
return 'The project page'
70+
71+
72+
@app.route('/about')
73+
def about():
74+
return 'The about page'
75+
76+
77+
"""
78+
/ 重定向行为:
79+
projects的URL,会自动补齐尾部'/';
80+
about的url,如果访问时尾部带了'/',会报错;
81+
"""
82+
83+
84+
@app.route('/')
85+
def index():
86+
return 'index'
87+
88+
89+
@app.route('/login')
90+
def login():
91+
return 'login'
92+
93+
94+
@app.route('/user/<username>')
95+
def profile(username):
96+
# app.logger.info('user: {}'.format(username))
97+
logger.info('user: {}'.format(username))
98+
return 'User %s' % username
99+
100+
101+
"""
102+
url_for()函数用于构建指定函数的URL。它把函数名称作为第一个参数,可以接受任意个关键字参数,每个关键字参数对应URL中的变量。
103+
未知变量讲添加到URL中作为查询参数。
104+
"""
105+
with app.test_request_context():
106+
print(url_for('index'))
107+
print(url_for('login'))
108+
print(url_for('login', next='/'))
109+
print(url_for('profile', username='John Doe'))
110+
111+
112+
@app.route('/method', methods=['GET', 'POST'])
113+
def method():
114+
if request.method == 'POST':
115+
return 'do post'
116+
else:
117+
return 'do show'
118+
119+
120+
# 如果支持GET方法,flask会自动添加HEAD方法支持;
121+
# url_for('static', filename='style.css')
122+
123+
124+
# flask使用Jinja2模板引擎,render_template方法可以渲染模板
125+
# flask会在templates文件夹内寻找模板
126+
@app.route('/hello/')
127+
@app.route('/hello/<name>')
128+
def hello(name=None):
129+
return render_template('hello.html', name=name)
130+
131+
132+
# error page
133+
@app.errorhandler(404)
134+
def page_not_found(error):
135+
return render_template('page_not_found.html'), 404

flask/demo/__init__.py

Whitespace-only changes.
1.51 KB
Binary file not shown.

flask/demo/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SQLALCHEMY_DATABASE_URI = "mysql://root:[email protected]:32769/flask"
2+
SQLALCHEMY_TRACK_MODIFICATIONS = True

flask/demo/demo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from flask import Flask
2+
from flask_sqlalchemy import SQLAlchemy
3+
4+
app = Flask(__name__)
5+
app.config['SECRET_KEY'] = 'dev'
6+
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:[email protected]:32769/flask'
7+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
8+
9+
db = SQLAlchemy(app)
10+
11+
12+
class Role(db.Model):
13+
__tablename__ = 'roles'
14+
id = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True)
15+
name = db.Column(db.String(32), nullable=False, unique=True, server_default='')
16+
17+
def __repr__(self):
18+
return '<Role %r>' % self.name
19+
20+
21+
class User(db.Model):
22+
__tablename__ = 'users'
23+
24+
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
25+
username = db.Column(db.String(64), nullable=False, unique=True, index=True)
26+
email = db.Column(db.String(128), unique=True)
27+
role_id = db.Column(db.Integer, nullable=False)
28+
29+
def __init__(self, username, email):
30+
self.username = username
31+
self.email = email
32+
33+
def __repr__(self):
34+
return '<User %r, Role id %r>' %(self.username, self.role_id)
35+
36+
37+
38+
39+

flask/templates/hello.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Hello from Flask</title>
6+
</head>
7+
<body>
8+
{% if name %}
9+
<h1>Hello {{ name }}!</h1>
10+
{% else %}
11+
<h1>Hello, World!</h1>
12+
{% endif %}
13+
</body>
14+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Page not Found</title>
6+
</head>
7+
<body>
8+
<h1>Sorry for lost!</h1>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)