2016-08-08 27 views
0

Ich habe ein paar URLs, die ich zum Filtern verwenden. Wenn ich für Werte suchen, um die spezifischen URLs bekomme ichEntfernen von Leerzeichen aus filternd url django tastypie

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

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

Alot von Werten einen Raum dazwischen Worte müssen verwendet werden. Wie kann ich %20 aus den Räumen entfernen und die URL habe saubere zurückzukehren:

Wunsch: api/v1/labels/?brand_city__city=Novi Sad keine %20 vorhanden

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 
     } 

Snippet Antwort

{ 
    "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 
    } 
} 

Antwort

0

überprüfen Sie die p ython Funktion urllib2.unquote

# you can convert your urls using urlib2 library 
path = urllib2.unquote("api/v1/labels/?brand_city__location__state_or_country=New%20York") 

Auch, wie unquote, eine andere Funktion unquote_plus können auch verwendet werden, die ersetzt auch Pluszeichen durch Leerzeichen, je nach Bedarf für unquoting Werte HTML-Formular. Verwenden Sie nach Ihrer Anforderung