Filtering datetime as ISO 8601 in URL doesn't work

253 views
Skip to first unread message

Daniel Gilge

unread,
Dec 25, 2017, 4:52:29 AM12/25/17
to Django REST framework
Hi,

I've got an issue I don't know where to ask (because there are Django, DRF and django-filter included) and how to handle it (I don't find a documentation or any issues on that) but I think this is the best place to start.

We have an API with a datetime field we want to filter with "greater than" using django-filter. That means we have an URL like /api/books/?published__gt=1994-11-05T08:15:30+05:00. That works fine as long as you don't have the "+" in the query value. (That means you can use timezones behind UTC ("-") and UTC with the "z" notation.)

My first question is:

1) Is ISO 8601 a good practice as query value in URIs? If not what is the best practice?

What happens is that Django's QueryDict is used which makes Use of Django's limited_parse_qsl (taken from some version of urlparse) which replaces the "+" by a " " (space) in query values.

2) How to solve this?

I've also created a test repository to make sure that no other packages caused the problem.

Julio Biason

unread,
Dec 25, 2017, 9:02:56 AM12/25/17
to django-res...@googlegroups.com
You solve it by doing what the Spec says: encode the “+” (same thing it is happening with space should Allen with your “+”.)


From: django-res...@googlegroups.com <django-res...@googlegroups.com> on behalf of Daniel Gilge <d.g...@gmail.com>
Sent: Monday, December 25, 2017 7:52:29 AM
To: Django REST framework
Subject: Filtering datetime as ISO 8601 in URL doesn't work
 
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Gilge

unread,
Dec 25, 2017, 9:42:57 AM12/25/17
to Django REST framework
Thanks for your quick reply! You're totally right! We didn't think of the url encoding.

If somebody else gets to this question: you can use Python's urllib.parse.quote to replace the reserved characters in urls.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages