python - negative integers in django -
i'm trying make query in postgresql database. need multiply -1 id before query.
def getrelation(request,id): #id = id * -1 #osmobject = get_object_or_404(planetosmpolygon,osm_id=int(id)) return httpresponse(id) #return httpresponse(osmobject.way.geojson)
this view. code works, however, if uncomment multiply, there nothing in browser. can't see negative id. mistake?
if uncomment get_object_404
, have :
invalid literal int() base 10: ''
that's why tried int()
.
this problem seems simple , don't understand why. begin in django.
thanks
parameters captured urls (your id
here) injected strings
you need coerce before start working it
something like
def getrelation(request, id): id = int(id) # rest of view
update (re: blank string)
python lets repeat strings overloading multiplication operator
>>> "foo" * 3 'foofoofoo'
when try multiply string (containing id, string) -1
, "-1 copies", returns empty string
>>> "foo" * -1 ''
or in case:
>>> "12" * -1 '' >>> int("12") * -1 -12
Comments
Post a Comment