본문 바로가기

Upstage AI Lab 2기

Upstage AI Lab 2기 [Day010] (1) Flask 기초

Upstage AI Lab 2기

2023년 12월 22일 (금) Day_010

 

Day_010 실시간 강의 (오전) :

파이썬 AI/데이터분석 과정 (패스트캠퍼스 김인섭 강사님)

 

cmd 창에서 >python app.py 로 실행

 

기본 format

from flask import Flask, render_template, jsonify

app = Flask(__name__)

@app.route('/')
#def function():
#    return render_template('index.html', feeds=data['feeds'])

if __name__ == '__main__':
    app.run(debug=True)
from flask import Flask, render_template, jsonify

app = Flask(__name__)

@app.route('/')
def main():
    return "<h1>Welcome Flask!</h1>"

# @app.route('/about')
# def about():
#     return "<h1>This is About page</h1>"

@app.route('/about/<user_name>')
def about(user_name):
    return f"<h1>This is page about {user_name}!!!</h1>"

@app.route('/api/v1/feeds')
def all_feeds():
    data = {
        'feeds' : [
            {'title': 'test title1', 'content': 'test content1'},
            {'title': 'test title2', 'content': 'test content2'},
            {'title': 'test title3', 'content': 'test content3'},
            {'title': 'test title4', 'content': 'test content4'}
        ]
    }
    # return jsonify(data)
    return render_template('index.html', feeds=data['feeds'])


if __name__ == '__main__':
    app.run(debug=True)