Django: Handling several page parameters

66 views Asked by At

I have several possible parameter to process in a page. Assume x0, x1, x2,..., x1000. It seems awkward to get and process them one by one by request.GET.get('x0'), request.GET.get('x1'), ...

Any idea to put them in a list, so that they can be processed in a loop.

1

There are 1 answers

2
xyres On BEST ANSWER

Since, request.GET is a dictionary, you can access its values like this:

for var in request.GET:
    value = request.GET[var]
    # do something with the value ...

Or if you want to put the values in a list:

val_list = []
for var in request.GET:
    var_list.append(request.GET[var])