2016-08-08 12 views
0

フィルタリングに使用しているいくつかのURLがあります。私は特定のURLを使用して値を検索すると、私は、使用されている値の多くは、言葉わたってるしきスペースを持つことになりますフィルタリングするURLから空白を削除するdjango tastypie

  1. api/v1/labels/?brand_city__location__state_or_country=New%20York

  2. api/v1/labels/?brand_city__city=Novi%20Sad

を取得します。どのように私はURLをスペースから%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

pをチェックしてくださいunquoting HTMLフォーム値のために必要とされるython機能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も、またスペースで置き換えプラス記号を使用することができます。あなたの要件に応じて使用

関連する問題