[PYTHON] A memorandum of understanding about django's QueryDict

This is the one used in request.POST. Note that it was necessary to confirm the difference in behavior with dict.

The feature is

--Pass the query string to create an instance --Immutable (but you can pass mutable = True) --Holding values in a list (inheriting MultiValueDict)

>>> from django.http import QueryDict
>>> qd = QueryDict('spam=1&egg=2')

#When you get it with get, a string is returned
>>> qd.get('spam')
u'1'

#Get list with getlist returns list
>>> qd.getlist('spam')
[u'1']

#Return to query string
>>> qd.urlencode()
u'egg=2&spam=1'

#Try to set the value
>>> qd['spam'] = 100
AttributeError: This QueryDict instance is immutable

# mutable=Make QueryDict with True
>>> qd2 = QueryDict('spam=1&egg=2', mutable=True)                                                                                                                                 
>>> qd2.get('spam')
u'1'
>>> qd2['spam'] = 100
>>> qd2.get('spam')
100

#Try converting to dict
>>> d = dict(qd)
>>> d.get('spam')
[u'1']

Recommended Posts

A memorandum of understanding about django's QueryDict
A memorandum about matplotlib
A memorandum about Nan.
elasticsearch_dsl Memorandum of Understanding
A memorandum about the warning of the pylint output result
A memorandum of kernel compilation
A memorandum about correlation [Python]
A memorandum about Python mock
A memorandum of using eigen3
A memorandum of files under conf.d
A memorandum of closure survey contents
A memorandum of understanding for the Python package management tool ez_setup
A memorandum of using Python's input function
A memorandum of speed of arbitrary degree diagonalization
Memorandum of python beginners About inclusion notation
A complete understanding of Python's object-oriented programming
Memorandum of Understanding when migrating with GORM
A memorandum of python string deletion process
A memorandum of trouble when formatting data
Memorandum of sed
A memorandum of calling Python from Common Lisp
A memorandum of studying and implementing deep learning
A memorandum of extraction by python bs4 request
A note about the python version of python virtualenv
Talking about array parameter transfer to django's QueryDict
A memorandum about the Python tesseract wrapper library
[Python] A rough understanding of the logging module
[Linux command] A memorandum of frequently used commands
[Python] A rough understanding of iterators, iterators, and generators
Django's basic memorandum
Memorandum about validation
About Django's ProxyModel
A list of stumbling blocks in Django's image upload
A miscellaneous summary of what I researched about Ansible
[PyTorch] A little understanding of CrossEntropyLoss with mathematical formulas
Analysis of measurement data ①-Memorandum of understanding for scipy fitting-
Memorandum of understanding for environment construction of AutoML library PyCaret
A story about changing the master name of BlueZ
A reminder about the implementation of recommendations in Python
Memorandum of fastText (editing)
memorandum of vi command
About all of numpy
About assignment of numpy.ndarray
About MultiIndex of pandas
A note about __call__
A note about subprocess
About variable of chainer
A note about mprotect (2)
A memorandum of stumbling on my personal HEROKU & Python (Flask)
A memo about the behavior of bowtie2 during multiple hits
[Introduction to AWS] A memorandum of building a web server on AWS
A story about clustering time series data of foreign exchange