#29208 closed Bug (wontfix)

Mistake in the documentation, request.POST['username'] is not working, but request.POST.get('username') is working!

Reported by: Marat Mkhitaryan Owned by: nobody
Component: Documentation Version: 2.0
Severity: Normal Keywords:
Cc: Marat, Mkhitaryan Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.login

username = request.POST['username']
password = request.POST['password']
# MultiValueDictKeyError
username = request.POST.get('username')
password = request.POST.get('password')
# No errors

Change History (2)

comment:1 Changed 17 months ago by Marat Mkhitaryan

Summary: Mistake in the documentation, request.POST['username'] is not working, but request.POST.get('username') is woring!Mistake in the documentation, request.POST['username'] is not working, but request.POST.get('username') is working!

comment:2 Changed 17 months ago by Claude Paroz

Resolution: wontfix
Status: newclosed

I wouldn't say this is a bug. The example assumes that request.POST contains username and password. If you use that in a context where it might not be the case, then yes, you should defensively use .get(). That's pure standard Python behaviour.

Note: See TracTickets for help on using tickets.
Back to Top