FE/Web

Flask 사용해보기 2

serin99 2023. 5. 9. 16:48
728x90

 

간단하게 웹 서버를 구축하기 위해 환경 구성을 위하여 세부 폴더와 소스코드를 작성한다.

 

 

<simpleweb.py>

from flask import Flask, render_template

app = Flask(__name__)
 
@app.route('/')
def index():
	return render_template('index.html')
    
@app.route('/header')
def header():
	return render_template('header.html')
    
@app.route('/link')
def link():
	return render_template('link.html')
    
@app.route('/text')
def text():
	return render_template('text.html')
    
@app.route('/list1')
def list1():
return render_template('list1.html')

@app.route('/list2')
def list2():
	return render_template('list2.html')

@app.route('/table')
def table():
	return render_template('table.html')

@app.route('/image')
def image():
	return render_template('image.html')

if __name__ == '__main__':
	app.run(debug=True, host='자신의 ip', port=5000)

 

 

<index.html>

 

<html>
<body>
Hello My Web
</body>
</html>

 

 

<header.html>

 

<html>
<head>
<title>HTML5 + CSS3 Text</title>
</head>
<body>
<h1> 1</h1>
<h2> 2</h2>
<h3> 3</h3>
<h4> 4</h4>
<h5> 5</h5>
<h6> 6</h6>
</body>
</html>

 

 

<link.html>

 

<html>
<head>
<title>HTML TEXT Basic Page</title>
</head>
<body>
<a href="http://naver.com/"> </a><br>
<a href="http://daum.net/"> </a><br>
</body>
</html>

 

 

<text.html>

 

<html>
<head>
<title>HTML TEXT Basic Page</title>
</head>
<body>
<h1><b>Lorem ipsum dolor sit amet</b></h1>
<h1><i>Lorem ipsum dolor sit amet</i></h1>
<h1><small>Lorem ipsum dolor sit amet</small></h1>
<h1>Lorem ipsum dolor <sub> sit amet</sub></h1>
<h1>Lorem ipsum dolor <sup> sit amet</sup></h1>
<h1><ins>Lorem ipsum dolor sit amet</ins></h1>
<h1><del>Lorem ipsum dolor sit amet</del></h1>
<hr>
<b>Lorem ipsum dolor sit amet</b><br>
<i>Lorem ipsum dolor sit amet</i><br>
<small>Lorem ipsum dolor sit amet</small><br>
Lorem ipsum dolor <sub> sit amet</sub><br>
Lorem ipsum dolor <sup> sit amet</sup><br>
<ins>Lorem ipsum dolor sit amet</ins><br>
<del>Lorem ipsum dolor sit amet</del><br>
</body>
</html>

 

 

<list1.html>

 

<html>
<head>
<title>HTML List Basic Page</title>
</head>
<body>
<ul>
    <li>사과</li>
    <li>바나나</li>
    <li>오렌지</li>
</ui>
</body>
</html>

 

 

<list2.html>

 

<html>
<head>
<title>HTML List Basic Page</title>
</head>
<body>
<ol>
   <li>사과</li>
   <li>바나나</li>
   <li>오렌지</li>
</ol>
</body>
</html>

 

 

<table.html>

 

<html>
<head>
<title>HTML Table Basic Page</title>
</head>
<body>
<table border="1">
<thead>
	<tr>
		<th>월</th>
		<th>화</th>
		<th>수</th>
		<th>목</th>
		<th>금</th>
	</tr>
</thead>
<tbody>
	<tr>
		<td>1교시</td>
		<td>영어</td>
		<td>국어</td>
		<td>과학</td>
		<td>미술</td>
		<td>기술</td>
	</tr>
	<tr>
		<td>2교시</td>
		<td>도덕</td>
		<td>체육</td>
		<td>영어</td>
		<td>수학</td>
		<td>사회</td>
	</tr>
</tbody>
</table>
</body>
</html>

 

python\simpleweb
python simpleweb.py

터미널에서 위와 같이 명령어를 입력하여 프로그램을 실행한다.

 

위와 같이 서버가 시작된 것을 확인한다.

728x90