1. 개요
각종 테스트에 사용할 간단 파이썬 애플리케이션을 만들어본다.
2. 구성
2.1. 상위 디렉토리 생성
mkdir -p sample-app
2.2. sample-app/main.py
sample-app
하위에 main.py
생성
from flask import Flask, render_template, request app = Flask(__name__) @app.route("/") def main(): model = {"title": "Hello DevOps Fans."} return render_template('index.html', model=model) if __name__ == "__main__": app.run(host='0.0.0.0', port=8080, debug=True, threaded=True)
2.3. sample-app/requirements.txt
Flask==1.1.1
2.4. sample-app/templates/layout.html
sample-app
하위에 templates
디렉토리 만들고 layout.html
생성
<!doctype html> <html lang="en"> <head> <title>{{model.title}}</title> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> </head> <body> <div class="container"> {% block content %}{% endblock %} <footer></footer> </div> </body> </html>
2.4. sample-app/templates/index.html
{% extends "layout.html" %} {% block content %} <div class="jumbotron"> <div class="container"> <h1>{{model.title}}</h1> </div> </div> {% endblock %}
3. 실행
cd sample-app sudo pip3 install -r requirements.txt
python3 main.py
그리고 8080 포트 접근하여 확인한다.
4. Git
cd sample-app git add --all
git config --global user.email "이 이메일 주소가 스팸봇으로부터 보호됩니다. 확인하려면 자바스크립트 활성화가 필요합니다."
git config --global user.name "Your Name"
git commit -a -m "Initial Commit"
git push origin master