Skip to content

Commit 12ac427

Browse files
committed
flask2
1 parent 374d16e commit 12ac427

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

4_2.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from flask import Flask #웹 어플리케이션 만드는 프레임 워크 flask
2+
from flask import render_template, request
3+
4+
#앱을 만들기 위한 코드
5+
app = Flask("SuperScrapper")
6+
7+
# @ = decorator...바로 아래에 있는 "함수"를 찾아서 decorate 해준다.
8+
# / 로 접속요청 시 파이썬 함수를 실행하도록 구축
9+
# @app.route("/")
10+
# def home():
11+
# return "Hello! welcome to my house"
12+
13+
# dynamic urls 사용 법
14+
# <> 를 placeholder 라고 한다.
15+
# 이렇게 쓸 경우 flask는 home2 함수를 username 인자와 함께 호출하려한다.
16+
# @app.route("/<username>")
17+
# def home2(username):
18+
# return f"Hello! your name is {username} "
19+
# 이런 dynamic urls 는 예를들어 instagram/developerYun 이렇게 입력하면
20+
# DB에서 username을 찾아서 결과를 띄워주는 방식이다.
21+
22+
23+
# html을 보여줄 수도 있다.
24+
# html 파일을 받아오기 위해서는 render_template를 import 해야한다.
25+
@app.route("/")
26+
def home3():
27+
return render_template("home3.html")
28+
29+
# 함수에 인자는 없지만, 사용자가 찾으려고 하는 단어는 가져오고싶다.
30+
# 따라서 requests를 import한다. 데이터를 웹사이트에 보내느것도 가져오는것도 requests
31+
@app.route("/report")
32+
def report():
33+
#name='word'의 arguments를 request가 뽑아온다.
34+
word = request.args.get('word')
35+
#flask가 html 파일을 쭉 보고 있다가
36+
# 변수들을 쭉 보고, 변수를 {{}} 안에 넣어줘서 사용자에게 보여준다.
37+
# 이를 rendering 이라고 한다.
38+
return render_template("report.html", searchingBy=word)
39+
40+
#repl.it 에서 구동하는 서버
41+
app.run(host='0.0.0.0')
42+

home3.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+
<title>Job Search</title>
5+
</head>
6+
<body>
7+
<h1>job search</h1>
8+
<!-- 웹에서 데이터를 보내는 기본 양식 -->
9+
<form action="/report" method="get">
10+
<input placeholder='what job do u want?' required name="word"/>
11+
<button>Search</button>
12+
</form>
13+
</body>
14+
</html>

report.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+
<title>job search</title>
5+
</head>
6+
<body>
7+
<h1>Search Results</h1>
8+
<h3>u are looking for {{searchingBy}}</h3>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)