Friday, July 30, 2010

Re: test's says post but request.method says GET

On Jul 30, 1:18 am, Phlip <> wrote:
> Django aficionados:
> Here's my test code:
>         from django.test.client import Client
>         self.client = Client()
>         from django.core.files.base import ContentFile
>         file_content = ContentFile(sample_inventory_update_cvs())
> = 'response.csv'
>         response = self.url,
>                                      data={'csv_file':file_content} )
> Disregard all that ContentFile nonsense (unless it's causing the bug).
> Inside the action code, I want to distinguish GETting from POSTing.
> One paints the page and the other absorbs new form data, as usual.
> However, when I print request.method, I get GET.
> Is this a bug in Client? or in (ahem) my comprehension?
> --
>   Phlip

What's the value of `self.url`? One possibility is that it doesn't end
with a slash, and you have the APPEND_SLASH setting set to True (the
default), so Django is redirecting from '/foo' to '/foo/'. A
redirected POST ends up as a GET.

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment