16👍
✅
This should work:
mstring = []
for key in request.GET.iterkeys(): # "for key in request.GET" works too.
# Add filtering logic here.
valuelist = request.GET.getlist(key)
mstring.extend(['%s=%s' % (key, val) for val in valuelist])
print '&'.join(mstring)
26👍
request.META['QUERY_STRING']
will give the complete query string
or if you want to get the list of values for a given key
ex: list of values for status then
request.GET.getlist('status')
- [Django]-Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events
- [Django]-How to view corresponding SQL query of the Django ORM's queryset?
- [Django]-Difference between @cached_property and @lru_cache decorator
8👍
I believe QueryDict.urlencode achieves your desired outcome if all you want to do is print out the QueryDict then just
print request.GET.urlencode()
should do the trick. Let me know if you were trying to do something else and I’ll try to help!
- [Django]-Django Rest Framework ImageField
- [Django]-Django MySQL error when creating tables
- [Django]-Django Template Language: Using a for loop with else
- [Django]-How to delete project in django
- [Django]-Displaying a Table in Django from Database
- [Django]-Writing unit tests in Django / Python
- [Django]-Django: Get an object form the DB, or 'None' if nothing matches
- [Django]-Django post_save preventing recursion without overriding model save()
- [Django]-Django ERROR: Invalid HTTP_HOST header: u'/run/myprojectname/gunicorn.sock:'
2👍
To obtain all the values from one. It’s better to use getlist("key", default=list)
. All the values from the key is stored in a list.
request.POST.getlist('key',default=list)
👤JekR
- [Django]-Override save on Django InlineModelAdmin
- [Django]-Django: Filter objects by integer between two values
- [Django]-Django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment varia
- [Django]-How to debug Django commands in PyCharm
- [Django]-Using a UUID as a primary key in Django models (generic relations impact)
- [Django]-Get last record in a queryset
0👍
There is a useful function in django http utils you can use:
>>> from django.utils.http import urlencode
>>> print(urlencode({"tag": [1, 2, 3], "sentence":2}, doseq=True))
'tag=1&tag=2&tag=3&sentence=2'
- [Django]-Django error <model> object has no attribute 'update'
- [Django]-Django, show ValidationError in template
- [Django]-Cancel an already executing task with Celery?
Source:stackexchange.com