kaki1013
2. 홈페이지 구현 본문
# 예시 코드
from flask import Flask
app = Flask(__name__)
topics = [
{'id': 1, 'title': 'html', 'body': 'html is ...'},
{'id': 2, 'title': 'css', 'body': 'css is ...'},
{'id': 3, 'title': 'javascruot', 'body': 'javascript is ...'}
]
@app.route('/')
def index():
liTags = ''
for topic in topics:
liTags = liTags + f'<li><a href="/read/{topic["id"]}/">{topic["title"]}</a></li>'
return f'''<!doctype html>
<html>
<body>
<h1><a href="/">WEB</a></h1>
<ol>
{liTags}
</ol>
<h2>Welcome</h2>
Hello, Web
</body>
</html>
'''
@app.route('/create/')
def create():
return 'Create'
@app.route('/read/<id>/')
def read(id):
print(id)
return 'Read ' + id
app.run(debug=True)
→ 태그들(HTML 코드)를 동적으로 생성
'버그바운티 스터디 > FLASK' 카테고리의 다른 글
5. 쓰기 기능 구현 (2) (0) | 2023.07.22 |
---|---|
4. 쓰기 기능 구현 (1) (0) | 2023.07.21 |
3. 읽기 기능 구현 (0) | 2023.07.21 |
1. Routing (0) | 2023.07.21 |
0. 수업 소개 및 개발환경 세팅 (0) | 2023.07.21 |