Flaskでブログアプリを作成する。
まずはHello, Flask!
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, Flask!"
if __name__=='__main__':
app.run(debug=True)
terminalで
$ python app.py
としてブラウザで http://127.0.0.1:5000 にアクセスする。
htmlを表示する
app.py
from flask import Flask, render_template #<-変更
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html') #<-変更
if __name__=='__main__':
app.run(debug=True)
Templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog App</title>
</head>
<body>
<h1>Hello, Flask!</h1>
</body>
</html>
1日目は以上!