LoginSignup
0
0

More than 5 years have passed since last update.

pyramid URLを動的にする

Posted at

1. 概要

  • pyramidでurlを動的に作りたい場合の設定の書き方メモ。

参考(http://docs.pylonsproject.jp/projects/pyramid-doc-ja/en/latest/)

http://localhost/hoge?uid=1

みたいにするのがいけてないので

http://localhost/hoge/1

こうしたいときとかに使う。

2. 環境

  • python 3.4.2
  • pyramid 1.5.7

3. 実装

pcreateで作成したひな形から作った場合で__init__.pyにルートを追加する際に、

config.add_route('hoge','hoge/{uid}')

ってやるとルーティングできる。
view側で値を使いたい場合はリクエストパラメータには入ってこないので、

uid = request.matchdict.get('uid')

ってやると使える。

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