Django のテスト クライアントを使用すると、リクエストを実行POSTし、リクエスト データをdict.
ただし、模倣<select multiple>または<input type="checkbox">フィールドのデータを送信する場合は、 data 内の単一のキーに対して複数の値を送信する必要がありますdict。
どうすればいいですか?
Django のテスト クライアントを使用すると、リクエストを実行POSTし、リクエスト データをdict.
ただし、模倣<select multiple>または<input type="checkbox">フィールドのデータを送信する場合は、 data 内の単一のキーに対して複数の値を送信する必要がありますdict。
どうすればいいですか?
最も簡単な方法は、値をlistまたはtupleで指定することdictです。
client.post('/foo', data={"key": ["value1", "value2"]})
または、値としてa を使用できMultiValueDictます。
from django.core.urlresolvers import reverse
from django.utils.datastructures import MultiValueDict
from django.utils.http import urlencode
form_data = {'username': 'user name',
'address': 'street',
'allowed_hosts': ["host1", "host2"]
}
response = client.post(reverse('new_user'),
urlencode(MultiValueDict(form_data), doseq=True),
content_type='application/x-www-form-urlencoded')