FlaskとYomanでHello World

FlaskとYomanでHello World

E555e865171b021035713018e5b7b689?s=128

Satoshi Miura

May 30, 2015
Tweet

Transcript

  1. FlaskͱYeomanͰHello,World 2015.05.30'Python౦ւ'27th

  2. ͓લͩΕΑ • Έ͏Β͞ͱ͠(@mursts) • PythonɺAndroid͕޷͖Ͱ͢ • ࢓ࣄͰ͸JavaɺPython͸झຯͰ͢ • ࠷ۙRaspberry9piΛങ͍·ͨ͠ •

    RadioϨίʔμʔҎ֎ͷ࢖͍ಓΛ໛ࡧத
  3. Agenda • Flaskͱ͸ • Yeomanͱ͸

  4. Flaskͱ͸

  5. Flask&is&a&microframework&for&Python&based&on&Werkzeug,&Jinja&2& and&good&inten>ons —"h$p://flask.pocoo.org/

  6. FlaskͷΠϯετʔϧ $ pip install flask

  7. Hello%World from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return "Hello World!" if __name__ == "__main__": app.run()
  8. Yeomanͱ͸

  9. The$web's$scaffolding$tool$for$modern$webapps 7$h8p:/ /yeoman.io/

  10. • Webͷ౷߹։ൃπʔϧ • YoͱGruntͱBowerͰߏ੒͞ΕΔ • Yoɿ.ͻͳܗΛ࡞੒ • Gruntɿ.λεΫϥϯφʔ • Bowerɿ.ύοέʔδϚωʔδϟ

  11. YeomanͷΠϯετʔϧ Node.jsͱnpm͕ඞཁͰ͢ $ npm install -g yo bower grunt-cli $

    yo --version 1.4.6 $ bower --version 1.4.1 $ grunt --version grunt-cli v0.1.13 grunt v0.4.5
  12. δΣωϨʔλͷΠϯετʔϧ h"ps:/ /github.com/rayokota/generator6angular6flask $ npm install -g generator-angular-flask GitɺPython2.7ɺSQLite͕ඞཁ

  13. Flaskͷͻͳܗ࡞੒ $ mkdir angular-flask $ cd angular-flask $ yo angular-flask

    +-+-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+ |a|n|g|u|l|a|r| |f|l|a|s|k| |g|e|n|e|r|a|t|o|r| +-+-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+ [?] What is the name of your application? # ΞϓϦ໊Λೖྗ
  14. . ├── Gruntfile.js ├── app ├── bower.json ├── config.py ├──

    db_create.py ├── db_downgrade.py ├── db_migrate.py ├── db_upgrade.py ├── generator.json ├── install.bat ├── install.sh ├── node_modules ├── package.json ├── run.py └── virtualenv.py
  15. app/ ├── __init__.py ├── models │ └── __init__.py ├── routes

    │ ├── __init__.py │ └── index.py ├── static │ ├── css │ ├── index.html │ ├── js │ ├── lib │ └── views └── templates
  16. # Virtualenvͷ؀ڥΛ࡞੒ $ ./install.sh # DBΛ࡞੒(app.db) $ flask/bin/python db_create.py #

    ΞϓϦΛىಈ $ flask/bin/python run.py
  17. None
  18. ը໘Λ௥Ճ͢Δ $ yo angular-flask:entity page1 # page1͸೚ҙͷը໘໊ You called the

    entity subgenerator with the argument page1. # ߲໨໊΍ܕͳͲʹ౴͍͑ͯ͘ Please specify an attribute: [?] What is the name of the attribute? Name [?] What is the type of the attribute? String [?] Enter the minimum length for the String attribute, or hit enter: 1 [?] Enter the maximum length for the String attribute, or hit enter: 10 [?] Is the attribute required to have a value? Yes [?] Would you like to enter another attribute or reenter a previous attribute? Yes [?] What is the name of the attribute? Age [?] What is the type of the attribute? Integer [?] Enter the minimum length for the String attribute, or hit enter: 0 [?] Enter the maximum length for the String attribute, or hit enter: 100 [?] Is the attribute required to have a value? Yes [?] Would you like to enter another attribute or reenter a previous attribute? No
  19. None
  20. None
  21. ͔͠͠ཪͰ͸Τϥʔ͕ൃੜɻɻɻ OperationalError: (OperationalError) no such table: page1 u'SELECT page1.id AS

    page1_id, page1."Name" AS "page1_Name", page1."Age" AS "page1_Age" \nFROM page1' () ςʔϒϧ͕ͳ͍Α͏ͳͷͰ࡞੒ $ flask/bin/python db_migrate.py # ը໘Λ௥Ճ͢ΔͨͼʹςʔϒϧΛ࡞੒͢Δ
  22. None
  23. σϞ

  24. PythonͷίʔυΛ1ߦ΋ॻ͘͜ͱͳ͘Flask-+-AngularJSΛ࢖ͬͨ WebΞϓϦΛ࡞Δ͜ͱ͕ग़དྷ·ͨ͠ɻ Django΍bo(leͷδΣωϨʔλ΋͋ͬͨͷͰ͍Ζ͍Ζ࡞ͬͯΈͯ ͸Ͳ͏Ͱ͠ΐ͏͔ɻ h"p:/ /yeoman.io/generators/

  25. ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ