LoginSignup
0
1

More than 3 years have passed since last update.

Djangoで同一名のパラメータをリストで取得する方法

Last updated at Posted at 2019-02-02

単純なのに少し詰まったのでメモ。

リクエストパラメータに同一名のものが複数あるとき、

http://fclef.jp/?id=1&id=2&id=3

こう書いて

ids = request.GET['id']

こうなった。

print(ids)
>>> '3'

思ってたんと違う。
恒例の書き方だと最後の要素しか取得しない。

全ての要素をリストで取得したいときはこう書く。

ids = request.GET.getlist('id')
print(ids)
>>>['1','2','3']
0
1
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
1