Skip to content

Commit 1c6831c

Browse files
author
moneyDboat
committed
add pythonweb
1 parent f08253b commit 1c6831c

File tree

7 files changed

+200
-0
lines changed

7 files changed

+200
-0
lines changed

pythonweb/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Flask, request, render_template
2+
3+
app = Flask(__name__)
4+
5+
@app.route('/', methods=['GET', 'POST'])
6+
def home():
7+
return render_template('home.html')
8+
9+
@app.route('/signin', methods=['GET'])
10+
def signin_form():
11+
return render_template('form.html')
12+
13+
@app.route('/signin', methods=['POST'])
14+
def signin():
15+
username = request.form['username']
16+
password = request.form['password']
17+
# 需要从request对象读取表单内容:
18+
if username=='admin' and password=='111':
19+
return render_template('signin-ok.html', username=username)
20+
return render_template('form.html', message='Bad username or password', username=username)
21+
22+
if __name__ == '__main__':
23+
app.run()

pythonweb/hello.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def application(environ, start_response):
2+
start_response('200 OK', [('Content-Type', 'text/html')])
3+
body = '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:]
4+
or 'web')
5+
return [body.encode('utf-8')]

pythonweb/server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# server.py
2+
# 从wsgiref模块导入:
3+
from wsgiref.simple_server import make_server
4+
# 导入我们自己编写的application函数:
5+
from hello import application
6+
7+
# 创建一个服务器,IP地址为空,端口是8000,处理函数是application:
8+
httpd = make_server('', 8000, application)
9+
print('Serving HTTP on port 8000...')
10+
# 开始监听HTTP请求:
11+
httpd.serve_forever()

pythonweb/templates/form.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<title>Please Sign In</title>
4+
</head>
5+
<body>
6+
{% if message %}
7+
<p style="color:red">{{ message }}</p>
8+
{% endif %}
9+
<form action="/signin" method="post">
10+
<legend>Please sign in:</legend>
11+
<p><input name="username" placeholder="Username" value="{{ username }}"></p>
12+
<p><input name="password" placeholder="Password" type="password"></p>
13+
<p><button type="submit">Sign In</button></p>
14+
</form>
15+
</body>
16+
</html>

pythonweb/templates/home.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Home</title>
4+
</head>
5+
<body>
6+
<h1 style="font-style:italic">Home</h1>
7+
</body>
8+
</html>

pythonweb/templates/signin-ok.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Welcome, {{ username }}</title>
4+
</head>
5+
<body>
6+
<p>Welcome, {{ username }}!</p>
7+
</body>
8+
</html>

pythonweb/templates/test.html

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<style>
6+
#header {
7+
background-color:black;
8+
color:white;
9+
text-align:center;
10+
padding:5px;
11+
}
12+
#menu {
13+
float:left;
14+
padding: 5px;
15+
}
16+
</style>
17+
</head>
18+
19+
<div id="header">
20+
<h1>猜你喜欢</h1>
21+
</div>
22+
23+
24+
25+
<div class="recommendations-bd">
26+
<dl class="" id="menu">
27+
<dt>
28+
<a href="https://movie.douban.com/subject/25980443/?from=subject-page" >
29+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2421855655.webp" alt="海边的曼彻斯特" class="" />
30+
</a>
31+
</dt>
32+
<dd>
33+
<a href="https://movie.douban.com/subject/25980443/?from=subject-page" class="" >海边的曼彻斯特</a>
34+
</dd>
35+
</dl>
36+
<dl class="" id="menu">
37+
<dt>
38+
<a href="https://movie.douban.com/subject/25958717/?from=subject-page" >
39+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2332944143.webp" alt="海蒂和爷爷" class="" />
40+
</a>
41+
</dt>
42+
<dd>
43+
<a href="https://movie.douban.com/subject/25958717/?from=subject-page" class="" >海蒂和爷爷</a>
44+
</dd>
45+
</dl>
46+
<dl class="" id="menu">
47+
<dt>
48+
<a href="https://movie.douban.com/subject/26628357/?from=subject-page" >
49+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2406624993.webp" alt="一个叫欧维的男人决定去死" class="" />
50+
</a>
51+
</dt>
52+
<dd>
53+
<a href="https://movie.douban.com/subject/26628357/?from=subject-page" class="" >一个叫欧维的男人决定去死</a>
54+
</dd>
55+
</dl>
56+
<dl class="" id="menu">
57+
<dt>
58+
<a href="https://movie.douban.com/subject/25895901/?from=subject-page" >
59+
<img src="https://img1.doubanio.com/view/movie_poster_cover/lpst/public/p2232247487.webp" alt="海街日记" class="" />
60+
</a>
61+
</dt>
62+
<dd>
63+
<a href="https://movie.douban.com/subject/25895901/?from=subject-page" class="" >海街日记</a>
64+
</dd>
65+
</dl>
66+
<dl class="" id="menu">
67+
<dt>
68+
<a href="https://movie.douban.com/subject/25834735/?from=subject-page" >
69+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2341555072.webp" alt="神奇队长" class="" />
70+
</a>
71+
</dt>
72+
<dd>
73+
<a href="https://movie.douban.com/subject/25834735/?from=subject-page" class="" >神奇队长</a>
74+
</dd>
75+
</dl>
76+
77+
<dl class="" id="menu">
78+
<dt>
79+
<a href="https://movie.douban.com/subject/25724855/?from=subject-page" >
80+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2259715855.webp" alt="房间" class="" />
81+
</a>
82+
</dt>
83+
<dd>
84+
<a href="https://movie.douban.com/subject/25724855/?from=subject-page" class="" >房间</a>
85+
</dd>
86+
</dl>
87+
<dl class="" id="menu">
88+
<dt>
89+
<a href="https://movie.douban.com/subject/26421442/?from=subject-page" >
90+
<img src="https://img1.doubanio.com/view/movie_poster_cover/lpst/public/p2370019558.webp" alt="滚烫的爱" class="" />
91+
</a>
92+
</dt>
93+
<dd>
94+
<a href="https://movie.douban.com/subject/26421442/?from=subject-page" class="" >滚烫的爱</a>
95+
</dd>
96+
</dl>
97+
<dl class="" id="menu">
98+
<dt>
99+
<a href="https://movie.douban.com/subject/26694988/?from=subject-page" >
100+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2342671303.webp" alt="比海更深" class="" />
101+
</a>
102+
</dt>
103+
<dd>
104+
<a href="https://movie.douban.com/subject/26694988/?from=subject-page" class="" >比海更深</a>
105+
</dd>
106+
</dl>
107+
<dl class="" id="menu">
108+
<dt>
109+
<a href="https://movie.douban.com/subject/26220650/?from=subject-page" >
110+
<img src="https://img1.doubanio.com/view/movie_poster_cover/lpst/public/p2333848819.webp" alt="雄狮" class="" />
111+
</a>
112+
</dt>
113+
<dd>
114+
<a href="https://movie.douban.com/subject/26220650/?from=subject-page" class="" >雄狮</a>
115+
</dd>
116+
</dl>
117+
<dl class="" id="menu">
118+
<dt>
119+
<a href="https://movie.douban.com/subject/26586432/?from=subject-page" >
120+
<img src="https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2369390663.webp" alt="契克" class="" />
121+
</a>
122+
</dt>
123+
<dd>
124+
<a href="https://movie.douban.com/subject/26586432/?from=subject-page" class="" >契克</a>
125+
</dd>
126+
</dl>
127+
</div>
128+
129+
</html>

0 commit comments

Comments
 (0)