Browse Source

render_template와 login페이지 추가

tobby48 5 years ago
parent
commit
d831e14a46

+ 19
- 0
src/main/python/kr/co/swh/lecture/opensource/flask/login.py View File

@@ -0,0 +1,19 @@
1
+from flask import Flask, redirect, url_for, request, render_template
2
+app = Flask(__name__)
3
+
4
+@app.route('/welcome/<name>')
5
+def welcome(name):
6
+   return '%s님 환영합니다.' % name
7
+
8
+@app.route('/login', methods = ['GET'])
9
+def login():
10
+    return render_template('login.html')
11
+
12
+@app.route('/submit', methods = ['POST'])
13
+def submit():
14
+   if request.method == 'POST':
15
+      user = request.form['myName']
16
+      return redirect(url_for('welcome', name=user))
17
+
18
+if __name__ == '__main__':
19
+    app.run(host="127.0.0.1", port="8080")

+ 2
- 2
src/main/python/kr/co/swh/lecture/opensource/flask/render_template.py View File

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

+ 10
- 0
src/main/python/kr/co/swh/lecture/opensource/flask/templates/login.html View File

@@ -0,0 +1,10 @@
1
+<!DOCTYPE html>
2
+<html>
3
+   <body>
4
+      <form action = "http://127.0.0.1:8080/submit" method = "post">
5
+         <p>Enter Name:</p>
6
+         <p><input type = "text" name = "myName" /></p>
7
+         <p><input type = "submit" value = "submit" /></p>
8
+      </form>
9
+   </body>
10
+</html>