I’m currently working on the Finxter app that I implemented using Python and Django. When slightly modifying the submit form that used a
"POST" HTTP method I wondered if this would be also possible with HTTP
"GET". And what is the technical difference anyway? 🧑💻
In this article, I quickly condense my research in case you had a similar question. Let’s get started! 👇
GET: The Data Gatherer 📚
The GET method is your data retriever, your information scout.
Whenever you’re visiting a website by typing that URL in your browser, you’re sending a GET request to the server. In Django-land, you’ll check for a GET request with
request.method == 'GET'.
Here’s the deal with GET: It carries request parameters in the URL.
That means your parameters are visible in the browser and stay in the browser history. It’s like airing your laundry— everyone can see it!
So, don’t use GET to transmit sensitive data, alright? Oh, and remember it’s also got a length limit.
POST: The Data Courier 📮
Now meet POST, the method that delivers data to the server. Think of it as your data courier.
It’s used when you’re sending data to the server for processing, like when submitting a form. You check for a POST request in Django with
request.method == 'POST'.
Unlike our friend GET, POST is a master of disguise 🕵️♂️. It sends data in the body of the request, making it a secure choice for transmitting sensitive info. POST doesn’t leave traces in the browser history or get cached, and there’s no limit on the data length.
GET and POST: The Form Handlers 📝
These two methods really shine when dealing with HTML forms.
When you load a form on a webpage, you’re typically fetching it using a GET request. But when you hit that “
Submit” button, if the form is set to
"POST", your browser whisks off a POST request to the server with the form data neatly packaged in the request’s body.
Here’s a snapshot of a POST form:
<form action="/submit_data" method="post"> <input type="text" name="data"> <input type="submit" value="Submit"> </form>
But remember, forms can use GET too.
<!-- Using GET --> <form action="/search" method="get"> <input type="text" name="q"> <input type="submit" value="Search"> </form> <!-- Using POST --> <form action="/login" method="post"> <input type="text" name="username"> <input type="password" name="password"> <input type="submit" value="Log in"> </form>
In those cases, the form data will join the URL party. It’s ideal for something like search forms where you aren’t changing server data and don’t mind sharing the request URL.
Keep coding, and see you on the server side! 😉
🧑💻 Recommended Tutorial: How I Created an URL Shortener App Using Django
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.