
app = Flask(__name__)
@app.route('/')
def home():
return render_template("home.html")
@app.route('/about/')
def about():
return render_template("about.html")
if __name__ == "__main__":
app.run(debug=True)
<html>
<head>
<title>Flask App</title>
<link rel="stylesheet" href={{url_for('static', filename='css/main.css')}}
</head>
<body>
<header>
<div class="container">
<h1 class="logo">Ardit's web app</h1>
<strong><nav>
<ul class="menu">
<li><a href="{{ url_for('home')}}">Home</a></li>
<li><a href="{{ url_for('about')}}">About</a></li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{%block content%}
{%endblock%}
</div>
</body>
</html>
{%block content%}
<div class="home">
<h1>My home page!</h1>
<p>This is a test website.</p>
</div>
{%endblock%}
{%block content%}
<div class="about">
<h1>My about page!</h1>
<p>This is a test website again.</p>
</div>
{%endblock%}
margin: 0;
padding: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #060;
}
/*
* Formatting the header area
*/
header {
background-color: #DFB887;
height: 35px;
width: 100%;
opacity: .9;
margin-bottom: 10px;
}
header h1.logo {
margin: 0;
font-size: 1.7em;
color: #fff;
text-transform: uppercase;
float: left;
}
header h1.logo:hover {
color: #fff;
text-decoration: none;
}
/*
* Center the body content
*/
.container {
width: 1200px;
margin: 0 auto;
}
div.home {
padding: 10px 0 30px 0;
background-color: #E6E6FA;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
div.about {
padding: 10px 0 30px 0;
background-color: #E6E6FA;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
h2 {
font-size: 3em;
margin-top: 40px;
text-align: center;
letter-spacing: -2px;
}
h3 {
font-size: 1.7em;
font-weight: 100;
margin-top: 30px;
text-align: center;
letter-spacing: -1px;
color: #999;
}
.menu {
float: right;
margin-top: 8px;
}
.menu li {
display: inline;
}
.menu li + li {
margin-left: 35px;
}
.menu li a {
color: #444;
text-decoration: none;
}
click==6.7
Flask==0.12.2
gunicorn==19.7.1
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
Werkzeug==0.12.2
web: gunicorn app4_script1:app
—> app4_script1은 웹서비스를 실행하는 python파일
—> app : 위 소스중 app4_script1.py를 보면 app = Flask(__name__) 한 부분이 있음. 즉, Flask 인스턴스를 받은 변수임.
7. runtime.txt : 동작환경으로 현재 동작하는 정확한 환경이라기 보다는 heroku에서 정해준 환경 중 하나를 선택해야 함.
Python-3.6.1
(https://devcenter.heroku.com/articles/python-runtimes) - Supported Python runtimes 부분을 보면 지원 환경이 나옴.
여기서는 3.5.x버전으로 환경을 구성하여, 가장 가까운 3.6.1로 설정함.
8. Heroku app 설정
$Heroku create appname
—> 중복된 appname이 있으면 생성되지 않음.(다른 사용자가 사용하는 것 포함.)
—> 성공하면, appname.herokuapp.com 으로 생성됨. (해당 페이지로 접근 가능함.)
9. 로컬 디렉토리(app4_script1.py가 있는) git 초기화
로컬 디렉토리로 이동 후
$git init
—> 로컬 디렉토리에 .git 파일 생성됨
10. git에 로컬 디렉토리 파일 추가
$git add .
11. git 이메일/사용자명 설정
$git config —global user.email “email@email.com"
$git config —global user.name “username"
12. commit
$git commit -m “first commit"
—> -m : message
13. heroku 에서 사용하고자 하는 app 설정
$git:remote —app appname
14. git에 push
$git push heroku master
15. 확인
$heroku open
댓글 없음:
댓글 쓰기