tobby48 5 years ago
parent
commit
67b1d0265d

+ 10
- 0
src/kr/co/swh/lecture/python/flask/render_template.py View File

@@ -0,0 +1,10 @@
1
+from flask import Flask
2
+app = Flask(__name__)
3
+
4
+@app.route('/')
5
+def hello_html():
6
+    # html file은 현 파일이 위치한 디렉토리 하위 templates 폴더에 위치해야 함
7
+    return "render_template('render_template.html')"
8
+
9
+if __name__ == "__main__":              
10
+    app.run(host="127.0.0.1", port="8080")

+ 33
- 0
src/kr/co/swh/lecture/python/flask/templates/index.ejs View File

@@ -0,0 +1,33 @@
1
+<html>
2
+	<head>
3
+  		<title><%= title %></title>
4
+		<link rel="stylesheet" type="text/css" href="css/style.css">
5
+  	</head>
6
+  	<body>
7
+	    <h1><%= title %></h1>
8
+	    <table>
9
+			<thead>
10
+				<tr>
11
+					<th>랭킹</th>
12
+					<th>키워드</th>
13
+					<th>빈도수</th>
14
+				</tr>
15
+			</thead>
16
+			<tbody>
17
+				<% for(var i=0; i<values.length; i++){ %>
18
+				<tr>
19
+					<td>
20
+		                <%= values[i].rank %>
21
+	            	</td>
22
+	            	<td>
23
+		                <%= values[i].keyword %>
24
+	            	</td>
25
+	            	<td>
26
+		                <%= values[i].num %>
27
+	            	</td>
28
+	            </tr>
29
+	        	<% } %>
30
+		    </tbody>
31
+		</table>
32
+  	</body>
33
+</html>

+ 8
- 0
src/kr/co/swh/lecture/python/flask/templates/jinja2.html View File

@@ -0,0 +1,8 @@
1
+<html>
2
+	<head>
3
+  		<title>SWH Sample</title>
4
+  	</head>
5
+  	<body>
6
+	    <h1>{{ user }}님 환영합니다.</h1>
7
+  	</body>
8
+</html>

+ 8
- 0
src/kr/co/swh/lecture/python/flask/templates/render_template.html View File

@@ -0,0 +1,8 @@
1
+<html>
2
+	<head>
3
+  		<title>SWH Sample</title>
4
+  	</head>
5
+  	<body>
6
+	    <h1>환영합니다.</h1>
7
+  	</body>
8
+</html>

+ 15
- 0
src/kr/co/swh/lecture/python/flask/url-for.py View File

@@ -0,0 +1,15 @@
1
+from flask import Flask, url_for
2
+app = Flask(__name__)
3
+@app.route("/hello/")
4
+def first():
5
+    return "안녕하세요"
6
+
7
+@app.route("/hello/<int:age>")
8
+def two(age):
9
+    "%d살이야." % age
10
+
11
+if __name__ == "__main__":
12
+    with app.test_request_context():
13
+        print(url_for('first'))
14
+        print(url_for('two', age=22))
15
+    #app.run(host="127.0.0.1", port="8080")