32
アアアアアアアアアアアアアア アアアア WEB アアア 2012 アアアア アアアア Monday, April 3, 2017

Lecture for Bootstrap and flask in Python

Embed Size (px)

Citation preview

Page 1: Lecture for Bootstrap and flask in Python

アントレプレナーシップ論講座 プレ講座 WEB 勉強会2012 年受講生

渡邊直樹Monday, April 3, 2017

Page 2: Lecture for Bootstrap and flask in Python

Self Introduction• 2016-2017 某外資 IT• 2014-2016 東京大学理学系大学院で素粒子研究• 2010-2014 東京大学教養学部理科一類 , 工学部物理工学科• 最近の趣味• 読書 : 3 月は 120 冊読んだ• ウェブ開発• 執筆

• 目標• より自由になる ( 人間関係、やりたいこと、自信、スキル、金など )

Monday, April 3, 2017 Entrepreneurship cources 2

Page 3: Lecture for Bootstrap and flask in Python

Agenda• Understand how the Internet works• Make a responsive landing page with Bootstrap

template• Make a simple web application with flask in Python

Monday, April 3, 2017 Entrepreneurship cources 3

Page 4: Lecture for Bootstrap and flask in Python

Client and server

Monday, April 3, 2017 Entrepreneurship cources 4

Page 5: Lecture for Bootstrap and flask in Python

At first, get a landing page template• Search “Bootstrap onepage” and click the top• Find “Landing page” and go.• Download a source code• Open index.html on your browser. It’s responsible

Monday, April 3, 2017 Entrepreneurship cources 5

Page 6: Lecture for Bootstrap and flask in Python

To know html and CSS• HTML contains text, img, checkbox, heading ….• CSS contains border, padding, color, font ….• To know easily, rename css folder to something and

open index.html

Monday, April 3, 2017 Entrepreneurship cources 6

Page 7: Lecture for Bootstrap and flask in Python

Bootstrap• Bootstrap is a UI framework published by Twitter.• 3.4% of the entire webpage are powered by bootstrap.• Cross browser compatibility• Responsive for smartphone and PC

Monday, April 3, 2017 Entrepreneurship cources 7

Page 8: Lecture for Bootstrap and flask in Python

Make a sample html 1 – simple html

Monday, April 3, 2017 Entrepreneurship cources 8

Page 9: Lecture for Bootstrap and flask in Python

Add bootstrap to html• Go to http://getbootstrap.com/getting-started/• Copy

Monday, April 3, 2017 Entrepreneurship cources 9

Page 10: Lecture for Bootstrap and flask in Python

Sample HTML 2 – add bootstrap• Add <link rel…> in header• Add <meta name="viewport" content="width=device-

width, initial-scale=1"> in header

Monday, April 3, 2017 Entrepreneurship cources 10

Page 11: Lecture for Bootstrap and flask in Python

Grid system

Monday, April 3, 2017 Entrepreneurship cources 11

Page 12: Lecture for Bootstrap and flask in Python

How to write class• class=“col-{size}-{number of columns}• Ex) class=“col-md-3”

• lg: 幅 1200px 以上の画面。デスクトップ PC など。• md: 幅 992px 以上の画面。デスクトップ PC など。• sm: 幅 768px 以上の画面。タブレットなど。• xs: 幅 768px 未満の画面。携帯など。

Monday, April 3, 2017 Entrepreneurship cources 12

Page 13: Lecture for Bootstrap and flask in Python

Sample3: responsive page

Monday, April 3, 2017 Entrepreneurship cources 13

Change typos 8 and 4 to 12 as.col-xs-12 col-md-6.col-sx-12 col-md-6↓

Page 14: Lecture for Bootstrap and flask in Python

Q. A column for smartphone,4 columns for desktop?• 3 minutes

Monday, April 3, 2017 Entrepreneurship cources 14

Page 15: Lecture for Bootstrap and flask in Python

Answer

<div class="col-xs-12 col-md-3">1</div> <div class="col-xs-12 col-md-3">2</div> <div class="col-xs-12 col-md-3">3</div> <div class="col-xs-12 col-md-3">4</div>

Monday, April 3, 2017 Entrepreneurship cources 15

Page 16: Lecture for Bootstrap and flask in Python

Sample4

Monday, April 3, 2017 Entrepreneurship cources 16

Page 17: Lecture for Bootstrap and flask in Python

Edit a bootstrap template• <title>…</title>• <h1>…</h1>• <h2>…</h2>• <p>…</p>• Download a photo to img folder and change path in

html <img src=“img/{filename}”>

I’ll show you what I edited in 10 minutes.Monday, April 3, 2017 Entrepreneurship cources 17

Page 18: Lecture for Bootstrap and flask in Python

Monday, April 3, 2017 Entrepreneurship cources 18

Page 19: Lecture for Bootstrap and flask in Python

Monday, April 3, 2017 Entrepreneurship cources 19

Page 20: Lecture for Bootstrap and flask in Python

Monday, April 3, 2017 Entrepreneurship cources 20

Page 21: Lecture for Bootstrap and flask in Python

Next, Create a web app in 4 steps

Monday, April 3, 2017 Entrepreneurship cources 21

Page 22: Lecture for Bootstrap and flask in Python

Step 1: Install Python• Install Python• Search “python” on the Internet• Install the latest version (3.6.1)

Monday, April 3, 2017 Entrepreneurship cources 22

Page 23: Lecture for Bootstrap and flask in Python

Set environment variables (Windows)• Search “environment” in Windows. • Click “ 環境変数を編集”• Add “;C:\Python36” to “Path” in “system environment

variables“ at the end.• Click “New” in “system environment variables“

and 変数名 : “PYTHONPATH”,変数値” C:\Python36\Scripts”

Monday, April 3, 2017 Entrepreneurship cources 23

Page 24: Lecture for Bootstrap and flask in Python

Run python• Search “cmd” and run “Command prompt”• Type “python” and hit enter• If you are on Mac and python version2.7 starts, try”python3”

instead.• type exit() to go back.

Monday, April 3, 2017 Entrepreneurship cources 24

Page 25: Lecture for Bootstrap and flask in Python

Step2: Install flask• On the terminal (mac) / command prompt (windows)• type “$pip install flask” and hit an enter (without $)

Monday, April 3, 2017 Entrepreneurship cources 25

Page 26: Lecture for Bootstrap and flask in Python

Step 3: Make a “app.py” filefrom flask import Flaskapp = Flask(__name__)

@app.route("/")def hello(): return "Hello World!"

if __name__ == "__main__": app.run()Monday, April 3, 2017 Entrepreneurship cources 26

Page 27: Lecture for Bootstrap and flask in Python

Run your app and go to your website• $python app.py• Then, go to http://localhost:5000• You will see “Hello Word!”

Monday, April 3, 2017 Entrepreneurship cources 27

Page 28: Lecture for Bootstrap and flask in Python

Step 4: Add below code to app.pyfrom flask import render_template

@app.route('/hello')@app.route('/hello/<name>')def hello(name=None): return render_template('hello.html', name=name)

Monday, April 3, 2017 Entrepreneurship cources 28

Page 29: Lecture for Bootstrap and flask in Python

Make a templates folder/app.py/templates /hello.html

Monday, April 3, 2017 Entrepreneurship cources 29

Page 30: Lecture for Bootstrap and flask in Python

hello.html<!doctype html><title>Hello from Flask</title>{% if name %} <h1>Hello {{ name }}!</h1>{% else %} <h1>Hello, World!</h1>{% endif %}

Monday, April 3, 2017 Entrepreneurship cources 30

Page 31: Lecture for Bootstrap and flask in Python

Run app (Ctrl+C to stop if it’s running)• Run by type >python app.py• Access to http://localhost:5000/hello/yourname

Monday, April 3, 2017 Entrepreneurship cources 31

Page 32: Lecture for Bootstrap and flask in Python

That’s all, folks. Here is citations• http://getbootstrap.com/getting-started• http://

bootstrap-sass.happyfuncorp.com/bootstrap-sass/layout/README.html

Monday, April 3, 2017 Entrepreneurship cources 32