Skip to content

Commit 5fbf998

Browse files
committed
1--27
1 parent 41f9897 commit 5fbf998

File tree

13 files changed

+317
-0
lines changed

13 files changed

+317
-0
lines changed

Web/Flask/AjaxTest/AjaxTest1.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
def hello():
88
return render_template("index.html")
99

10+
1011
@app.route('/test2')
1112
def test():
1213
return render_template("index2.html")
@@ -27,6 +28,16 @@ def test5():
2728
return render_template("index5.html")
2829

2930

31+
@app.route('/test6')
32+
def test6():
33+
return render_template("index6.html")
34+
35+
36+
@app.route('/test7')
37+
def test7():
38+
return render_template("index7.html")
39+
40+
3041
@app.route('/api', methods=['POST', 'GET'])
3142
def api():
3243
if request.method == "GET":
@@ -50,5 +61,41 @@ def api():
5061
return jsonify(data)
5162

5263

64+
@app.route('/login1', methods=['GET'])
65+
def login1():
66+
return render_template('login1.html')
67+
68+
69+
@app.route('/login2', methods=['GET'])
70+
def login2():
71+
return render_template('login2.html')
72+
73+
74+
@app.route('/loginapi', methods=['GET', 'POST'])
75+
def login_api():
76+
if request.method == 'GET':
77+
name = request.args.get('username')
78+
age = request.args.get('age')
79+
pwd = request.args.get('password')
80+
data = {
81+
'name': name,
82+
'age': age,
83+
'pwd': pwd
84+
}
85+
print(data)
86+
return jsonify(data)
87+
if request.method == 'POST':
88+
name = request.form['username']
89+
age = request.form['age']
90+
pwd = request.form['password']
91+
data = {
92+
'name': name,
93+
'age': age,
94+
'pwd': pwd
95+
}
96+
print(data)
97+
return jsonify(data)
98+
99+
53100
if __name__ == '__main__':
54101
app.run(debug=True)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>段子查询系统</title>
6+
<script src="/static/js/utils.js"></script>
7+
</head>
8+
<body>
9+
<ul id="wrap"></ul>
10+
<script>
11+
// 列表接口:https://api.apiopen.top/getJoke
12+
// 详情接口:https://api.apiopen.top/getSingleJoke?sid=段子id
13+
utils.fetch("https://api.apiopen.top/getJoke", null, true).then(function (resp) {
14+
console.log(resp);
15+
let html = '';
16+
resp.result.forEach(function (item) {
17+
html += `
18+
<li>
19+
<h3>${item.text}</h3>
20+
<button data-id="${item.sid}">查看作者</button>
21+
</li>
22+
`
23+
});
24+
document.querySelector('#wrap').innerHTML = html;
25+
});
26+
27+
document.querySelector("#wrap").onclick = function (e) {
28+
let target = e.target;
29+
if (target.tagName.toLowerCase() === 'button'){
30+
let sid = target.getAttribute('data-id');
31+
utils.fetch('https://api.apiopen.top/getSingleJoke',{sid: sid}, true).then(function (resp) {
32+
console.log(resp);
33+
let name = resp.result.name;
34+
let b = document.createElement("b");
35+
b.innerHTML = name;
36+
target.parentNode.appendChild(b);
37+
});
38+
}
39+
}
40+
</script>
41+
</body>
42+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>段子查询系统原生fetch的使用</title>
6+
</head>
7+
<body>
8+
<ul id="wrap"></ul>
9+
<script>
10+
// 列表接口:https://api.apiopen.top/getJoke
11+
// 详情接口:https://api.apiopen.top/getSingleJoke?sid=段子id
12+
fetch("https://api.apiopen.top/getJoke")
13+
.then(function (resp) {
14+
return resp.json();
15+
})
16+
.then(function (resp) {
17+
console.log(resp);
18+
let html = '';
19+
resp.result.forEach(function (item) {
20+
html += `
21+
<li>
22+
<h3>${item.text}</h3>
23+
<button data-id="${item.sid}">查看作者</button>
24+
</li>
25+
`
26+
});
27+
document.querySelector('#wrap').innerHTML = html;
28+
});
29+
30+
document.querySelector("#wrap").onclick = function (e) {
31+
let target = e.target;
32+
if (target.tagName.toLowerCase() === 'button') {
33+
let sid = target.getAttribute('data-id');
34+
fetch(`https://api.apiopen.top/getSingleJoke?sid=${sid}`)
35+
.then(function (resp) {
36+
return resp.json();
37+
})
38+
.then(function (resp) {
39+
console.log(resp);
40+
let name = resp.result.name;
41+
let b = document.createElement("b");
42+
b.innerHTML = name;
43+
target.parentNode.appendChild(b);
44+
});
45+
}
46+
}
47+
</script>
48+
</body>
49+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>登录get</title>
6+
</head>
7+
<body>
8+
<form action="/loginapi" method="get">
9+
<input type="text" name="username" placeholder="用户名"><br>
10+
<input type="text" name="age" placeholder="年龄"><br>
11+
<input type="text" name="password" placeholder="密码"><br>
12+
<input type="submit">
13+
</form>
14+
</body>
15+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>登录post</title>
6+
</head>
7+
<body>
8+
<form action="/loginapi" method="post" enctype="application/x-www-form-urlencoded">
9+
<input type="text" name="username" placeholder="用户名"><br>
10+
<input type="text" name="age" placeholder="年龄"><br>
11+
<input type="text" name="password" placeholder="密码"><br>
12+
<input type="submit">
13+
</form>
14+
</body>
15+
</html>

Web/Flask/FlaskBase/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web/Flask/FlaskBase/.idea/FlaskBase.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web/Flask/FlaskBase/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web/Flask/FlaskBase/.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web/Flask/FlaskBase/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)