-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add form query parameter documentation #18348
base: main
Are you sure you want to change the base?
Conversation
680db73
to
c30738e
Compare
c30738e
to
f287444
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you seen this at the top of the section?
django/docs/topics/forms/index.txt
Lines 56 to 88 in f287444
``GET`` and ``POST`` | |
-------------------- | |
``GET`` and ``POST`` are the only HTTP methods to use when dealing with forms. | |
Django's login form is returned using the ``POST`` method, in which the browser | |
bundles up the form data, encodes it for transmission, sends it to the server, | |
and then receives back its response. | |
``GET``, by contrast, bundles the submitted data into a string, and uses this | |
to compose a URL. The URL contains the address where the data must be sent, as | |
well as the data keys and values. You can see this in action if you do a search | |
in the Django documentation, which will produce a URL of the form | |
``https://docs.djangoproject.com/search/?q=forms&release=1``. | |
``GET`` and ``POST`` are typically used for different purposes. | |
Any request that could be used to change the state of the system - for example, | |
a request that makes changes in the database - should use ``POST``. ``GET`` | |
should be used only for requests that do not affect the state of the system. | |
``GET`` would also be unsuitable for a password form, because the password | |
would appear in the URL, and thus, also in browser history and server logs, | |
all in plain text. Neither would it be suitable for large quantities of data, | |
or for binary data, such as an image. A web application that uses ``GET`` | |
requests for admin forms is a security risk: it can be easy for an attacker to | |
mimic a form's request to gain access to sensitive parts of the system. | |
``POST``, coupled with other protections like Django's :doc:`CSRF protection | |
</ref/csrf/>` offers more control over access. | |
On the other hand, ``GET`` is suitable for things like a web search form, | |
because the URLs that represent a ``GET`` request can easily be bookmarked, | |
shared, or resubmitted. |
I think the example could perhaps be shortened and reference the discussion section above, using :ref:`ref-get-and-post`
and adding .. _ref-get-and-post:
above the "GET and POST" section?
The new example could for instance start: "With the shortcomings of GET-based form submission in mind (...)"
Yes, that's section I mention in the thread
Do you mind suggesting what you think we should remove? The intent of the documentation change in this pr is so when a new user looks in the documentation for "how do I use query params in a view?", there is an example for them to see. I understand that the code is pretty much the same as a POST request, but I still think it's valuable. It's also perfectly fine for someone else to think that we don't need to add this to the docs and we can close the pr.
I agree, good idea. Pretty much all of the words provide context specific to the example, so once you suggest a change to the example I can change the words, and include your |
Trac ticket number
N/A
Branch description
From the conversation in this thread, I thought it was a good idea to add specific form documentation for processing query paramters with a form.
Checklist
main
branch.