Case inconsistency

23 views
Skip to first unread message

Matthew Pava

unread,
May 9, 2018, 9:02:16 PM5/9/18
to django...@googlegroups.com

I came across an interesting issue recently.  I had a form with an action set to “GET”.  The corresponding view was a django-rest-framework view that was just supposed to allow for GET requests.  However, I couldn’t get it to work because drf was expecting lower case names, and it turns out that HTML5 expects a lowercase action set to “get”.

 

Yet the request variables are capitalized.

request.GET

request.POST

 

I suppose that we’re saying that those variables are “constants” and should follow the naming convention of capitalizing them.  They are immutable dictionaries after all.  So I guess I’ve answered my own question.

Melvyn Sopacua

unread,
May 9, 2018, 11:21:26 PM5/9/18
to django...@googlegroups.com
On woensdag 9 mei 2018 23:00:06 CEST Matthew Pava wrote:
> I came across an interesting issue recently. I had a form with an action
> set to "GET". The corresponding view was a django-rest-framework view that
> was just supposed to allow for GET requests. However, I couldn't get it to
> work because drf was expecting lower case names, and it turns out that
> HTML5 expects a lowercase action set to "get".

HTML is not your reference (and case insensitive to boot). HTML does not make
requests, it just specifies how responses are rendered. HTTP makes requests:
https://tools.ietf.org/html/rfc2616#page-36
--
Melvyn Sopacua

Jelmer Draaijer

unread,
May 9, 2018, 11:46:33 PM5/9/18
to Django users
If you like to read, and I suppose you do, here you go: https://stackoverflow.com/questions/4106544/post-vs-post-get-vs-get

I remeber this of my PHP days, $_SERVER['REQUEST_METHOD'] equals post or POST?

I think https://stackoverflow.com/a/4106575 answers your question.

Matthew Pava

unread,
May 10, 2018, 1:41:15 PM5/10/18
to django...@googlegroups.com
My comment was stated inaccurately. The method attribute was set to "GET" on the form element. It only worked when I set it to "get".
I learned XHTML (strict), which requires elements and attributes to be lowercase (which, for some reason, I violated when I set the attribute to "GET"). I forgot that that requirement was lifted with HTML5.

Your reference is interesting because it seems to imply that the method attribute has to be uppercase. Maybe the browser translates it to uppercase before sending it to the server? But then that doesn't explain why I got two different results based on the case of the method attribute.
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5432858.BvN9p53GFH%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
May 10, 2018, 7:56:55 PM5/10/18
to django...@googlegroups.com

On donderdag 10 mei 2018 15:39:21 CEST Matthew Pava wrote:

 

> Your reference is interesting because it seems to imply that the method

> attribute has to be uppercase. Maybe the browser translates it to

> uppercase before sending it to the server?

 

Again, HTML and requests are not strictly related. Requests are made using HTTP and yes, the browser is responsible for making that request. HTML has four ways of instructing the browser to make a request:

 

- A <form> submission

- <a> Hyperlink

- A src property of a resource reference (through img / script / link etc tags)

- A <meta> refresh tag

 

And yes, HTTP request methods are uppercase:

 

% telnet localhost 80

....

Escape character is '^]'.

get / http/1.1

HTTP/1.1 400 Bad Request

 

Now with capitals:

Escape character is '^]'.

GET / HTTP/1.1

Host: localhost

 

HTTP/1.1 301 Moved Permanently

 

> But then that doesn't explain

> why I got two different results based on the case of the method attribute.

 

Lowercase `get` is a common method, for one on all dictionary-like objects in Python. But the get method isn't implemented on standard Django Request objects. So even reading your original message, I couldn't tell you what went wrong. You probably analyzed the bug wrong as there are a few close but not quite the same things in the whole stack:

 

- HTML Form's method attribute

- A view that has a get() method that handles HTTP GET requests

- Django's HttpRequest object

- It's GET / POST dictionaries

- Which have a get() method

 

I've never come accross a browser that accepted only lowercase HTML attributes, although it may have been possible in the dark ages of XHTML 1.1 strict mode. I'd be thoroughly surprised if the only changing the case of the form's method attribute from `get` to `GET` would change anything.

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages