0330

1. 학습내용

https://flask.palletsprojects.com/en/2.1.x/
플라스크 설치

$ pip install Flask
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

app.run()

glitch.com
flask 검색
server.py
remix your own 수정
preview 보기
terminal
start.sh에서 python3 server.py로 바꾸기

from flask import Flask
import random

app = Flask(__name__)

@app.route("/")
def hello_world():
    return '<strong>random</strong> : ' + str(random.random())

app.run()
라우팅
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return 'Home'

@app.route("/create/")
def create():
    return 'Create'

@app.route("/update/")
def create():
    return 'Update'

app.run()
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return '''
      <html>
          <body>
              <h1><a href="/"><WEB></a></h1>
              <ol>
                  <li><a href="/read/1/">html</a></li>
                  <li><a href="/read/2/">css</a></li>
                  <li><a href="/read/3/">js</a></li>
              </ol>
              <h2>Read</h2>
              Hello, Read!
          </body>
      </html>
      '''

@app.route("/read/1/")
def read():
    return '''
	내용
    '''
from flask import Flask

app = Flask(__name__)

topics = [
	{"id":1, "title":"html", "body":"html is ..."},
	{"id":2, "title":"css", "body":"css is ..."}
]	

@app.route("/")
def index():
	liTags = ''
	for topic in topics:
		liTags = liTags + f'<li><a href="/read/{topic["id"]}/">{topic["title"]}</a></li>'
	retun f'''
      <html>
          <body>
              <h1><a href="/"><WEB></a></h1>
              <ol>
                  {liTags}
              </ol>
              <h2>Read</h2>
              Hello, Read!
          </body>
      </html>
      '''
  1. 어려웠던 점
    .

  2. 해결방법
    .

  3. 학습소감
    플라스크는 처음

좋은 웹페이지 즐겨찾기