LoginSignup
1
2

More than 5 years have passed since last update.

web2pyメモ:ハローワールド

Posted at

まずはインストール

その後は

python web2py.py -a 'password' -i 127.0.0.1 -p 8000

アプリケーション作成

python web2py.py -S appName

appName/views/default/index.html とかが作られる

ハローワールドする:appName/controllers/default.py

def index():
   return "Hello,World!"

サーバーを起動してチェックすると確かにできてる(URIは.../index)

テンプレートに組み込んで表示するには

def index():
   return dict(message="Hello!")

テンプレート内にスクリプトを組み込む

<body>
   {{for i in range(3):}}
      {{=message}}<br/>       <!-- {{=値}}で値をHTMLに出力 -->
   {{pass}}                   <!-- コントローラー関数で渡した辞書要素は変数として利用可 -->
</body>
1
2
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
1
2