How can one query parameter carry several dataset tags?
urlencode with doseq=True expands a sequence into repeated keys and escapes each item separately.
Python example and interpretation
Tags a b and x/y should travel as separate values. Agree with the receiver that repeated keys denote a list instead of combining them with an ambiguous comma.
from urllib.parse import urlencode
urlencode({'tag':['a b','x/y']},doseq=True)Result 'tag=a+b&tag=x%2Fy'
中文
一个筛选参数包含多个标签时怎样编码查询串?
urlencode 的 doseq=True 将序列值展开成多个同名键值对,并转义每一项。
Python 算例与适用条件
标签“a b”和“x/y”应独立传递,不能简单拼成一串逗号。接收端需约定同名参数表示列表。
from urllib.parse import urlencode
urlencode({'tag':['a b','x/y']},doseq=True)结果 'tag=a+b&tag=x%2Fy'