LearnThatStack Ace your next interview
Flask · question
Question 8 of 60

What's the difference between request.form, request.args, and request.get_json()?

beginner
← All Flask questions
Re-explain

They read three different parts of a request. request.args is the URL query string, request.form is a form-encoded body, and request.get_json() parses a JSON body.

request.args request.form request.get_json()
Source Query string after ? Request body Request body
Content type Any application/x-www-form-urlencoded or multipart/form-data application/json
Returns MultiDict of strings MultiDict of strings Parsed dict or list
When the data is absent get() returns None get() returns None 415 error, or None with silent=True
# URL: /api?page=1
# Body: {"name": "John"}

@app.route('/api', methods=['POST'])
def api():
    page = request.args.get('page')        # "1"
    name = request.get_json()['name']      # "John"
    username = request.form.get('username') # None, because the body is JSON

A request has only one body, so form and get_json() never both get data from the same request. That is why username is None above. When either source is fine, request.values combines args and form. Use args for filters and paging, form for HTML form posts, and get_json() for API clients.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Flask cheatsheet.

← Back to all Flask questions
Pro · $10/mo

51 of 60 Flask answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime