LoginSignup
0
0

More than 5 years have passed since last update.

PTVSでFlaskアプリの作成とデプロイ

Last updated at Posted at 2016-11-09

Flaskとは

Flaskは、Python用のマイクロWeb開発フレームワークです。 Jinja2テンプレートエンジンとWerkzeugWSGIツールキットに依存しています。

Python Tools 2.2 for Visual Studioを使用したFlaskアプリ開発

1. Visual Studioを起動し

【新しいプロジェクト】▶︎【Python/Web】▶︎【Flask Web Projet】
を選択し、プロジェクトを作成する
1.png

2. 作成したプロジェクトをRUNする

2.png

3.png

3.新しいHTMLを作成する

【プロジェクト】▶︎【template】▶︎【右クリック/追加】
で空のHTMLを作成する
4HTML作成.png

4.空のHTMLにコードを記入

test.html
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Hello</title>
</head>
<body>
    Hello World
</body>
</html>

view.py内のhome()をコメントアウトし、新しくtest.html(新しく作ったHTML)を読み込ませるように書きます。

view.py
def home():
    return render_template('test.html')

"""
def home():
    return render_template(
        'index.html',
        title='Home Page',
        year=datetime.now().year,
    )
"""

5. 実行するとHello Worldが表示される

5表示.png

6. デプロイする

【プロジェクト/右クリック】▶︎【公開】
6公開.png

7.png

8.png

Web App nameとApp Service planの項目で新しく任意の名前を決める
9.png

ここは確認のみ! 特に変更なければ発行
10.png

最後にAzure上に作成したアプリを確認します。
【App Service】▶︎【APP名】▶︎【概要】
URLをクリックすると開きます!
11.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0