1👍
Another solution is creating a copy of the request object… Normally, you can not iterate through a request.GET or request.POST object, but you can do such operations on the copy:
res_set = request.GET.copy()
for item in res_set['myvar']:
item
...
- [Django]-How to force Django models to be released from memory
- [Django]-How do I migrate a model out of one django app and into a new one?
- [Django]-Is this the right way to do dependency injection in Django?
1👍
When creating a query string from a QueryDict object that contains multiple values for the same parameter (such as a set of checkboxes) use the urlencode() method:
For example, I needed to obtain the incoming query request, remove a parameter and return the updated query string to the resulting page.
# Obtain a mutable copy of the original string
original_query = request.GET.copy()
# remove an undesired parameter
if 'page' in original_query:
del original_query['page']
Now if the original query has multiple values for the same parameter like this:
{…’track_id’: [‘1’, ‘2’],…} you will lose the first element in the query string when using code like:
new_query = urllib.parse.urlencode(original_query)
results in…
...&track_id=2&...
However, one can use the urlencode method of the QueryDict class in order to properly include multiple values:
new_query = original_query.urlencode()
which produces…
...&track_id=1&track_id=2&...
- [Django]-Django create userprofile if does not exist
- [Django]-Referencing multiple submit buttons in django
- [Django]-"<Message: title>" needs to have a value for field "id" before this many-to-many relationship can be used.