我有几个用于过滤的网址。当我使用我得到的特定网址查找值时
api/v1/labels/?brand_city__location__state_or_country=New%20York
api/v1/labels/?brand_city__city=Novi%20Sad
使用的很多值在单词之间会有一个空格。如何从空格中删除%20
并让网址更加清晰:
所需:api/v1/labels/?brand_city__city=Novi Sad
没有%20
在场
api.py
class LocationResource(ModelResource):
class Meta:
filtering = {
"state_or_country": ALL
}
class CityResource(ModelResource):
location = fields.ForeignKey(LocationResource, 'location', full=True)
class Meta:
filtering = {
"city": ALL,
"location": ALL_WITH_RELATIONS
}
class LabelResource(ModelResource):
brand_city = fields.ForeignKey(CityResource, 'brand_city', full=True)
class Meta:
filtering = {
"brand_category": ALL,
"brand_city": ALL_WITH_RELATIONS
}
代码段回复
{
"labels": [
{
"brand_city": {
"city": "Manhattan",
"location": {
"location_choices": "State",
"state_or_country": "New York"
}
}
}
],
"meta": {
"limit": 6,
"next": null,
"offset": 0,
"previous": null,
"total_count": 1
}
}
答案 0 :(得分:0)
查看python函数urllib2.unquote
# you can convert your urls using urlib2 library
path = urllib2.unquote("api/v1/labels/?brand_city__location__state_or_country=New%20York")
此外,与unquote
一样,也可以使用另一个函数unquote_plus
,它也可以按空格替换加号,这是取消引用HTML表单值所必需的。根据您的要求使用