Thank you Tom.

Somehow it seemed strange to test this view using client.get('/page/', {
'filter': 'one and two'})
but I get why it is like this.

Cheers,
Eneko


On Monday, April 20, 2015 at 3:30:55 PM UTC+2, Tom Evans wrote:
>
> On Sat, Apr 18, 2015 at 12:13 PM, Eneko Illarramendi 
> <eneko.ill...@gmail.com <javascript:>> wrote: 
> > Previously posted in SO: 
> > 
> http://stackoverflow.com/questions/29703930/testing-request-parameters-in-django-behaves-differently
>  
> > ----------------------- 
> > 
> > I have a Django View that uses a query parameter to so some content 
> > filtering. Something like this: 
> > 
> > /page/?filter=one+and+two 
> > /page/?filter=one,or,two 
> > 
> > I have noticed that Django converts the + to a space 
> > (request.GET.get('filter') returns one and two), and I´m OK with that. I 
> > just need to adjust the split() function I use in the View accordingly. 
>
> The arguments in a query string are urlencoded. Spaces are urlencoded 
> as '+'. Django's request.GET is a dict like object with the query 
> string arguments decoded. 
>
> > 
> > But... 
> > 
> > When I try to test this View, and I call: 
> > 
> > from django.test import Client 
> > client = Client() 
> > client.get('/page/', {'filter': 'one+and+two'}) 
>
> The test client takes a dictionary of raw strings, not urlencoded 
> strings. If you like, you are telling it to test the URL 
> '/page/?filter=one%2Band%2Btwo', as '+' is urlencoded as '%2B'. 
>
> Django is consistent, the test client takes raw un-encoded strings, 
> and request.GET delivers raw un-encoded strings. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/274a6eb9-dfa5-42ba-aff9-d564fad4e0c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to