WHile requesting from GET method, The url is created like
<your_url>?paths=path1&paths=path2&paths=path3...
This can be very long if there are large number of paths.
I want to request the paths through the POST method because the request lines are too large in the url created by the GET method. Is there any alternatives for
request.GET.getlist('paths')
if the paths are very long, then it shows Bad Request, Request Line too large.
There is an alternative for this:
request.POST.getlist('paths')
What will be the equivalent way to pass the data in the query string in the template so that the url will not be very long and all files can be downloaded?
views.py
def test_download(request):
paths = request.GET.getlist('paths')
context ={'paths': paths}
response = HttpResponse(content_type='application/zip')
zip_file = zipfile.ZipFile(response, 'w')
for filename in paths:
zip_file.write(filename)
zip_file.close()
response['Content-Disposition'] = 'attachment; filename='+'converted files'
return response
templates
<a href ="{% url 'test_download' %}?{% for path in paths %}paths={{ path|urlencode }}&{% endfor %}">Converted Files</a>
question from:
https://stackoverflow.com/questions/65839418/what-is-the-alternative-of-passing-array-to-the-urlurl-too-long 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…