There is a request object of class <class 'django.core.handlers.wsgi.WSGIRequest'> . It looks like this (there may be different parameter values):
<WSGIRequest: GET '/compare?type=all&type1=transit> I get it to a function and pass it to another function in the same place:
def compareStats(request): ... data1 = get_stats(request) ... data2 = get_stats(request) That is, get_stats I need to call twice. And the question is this: I cannot change the get_stats function, but it takes only type as an argument. Is there any way based on the received request to create a new request in which to replace the value of type with the value of type1 ?
Update on the issue in the comments.
What is the problem: the function get_stats gets the values from the database in the form of a json-array. To do this, you need to send a request to the database, in which the values received from the request are substituted. Something like
sql = """ select data, attr from record where type = {0}""".format(_type) cursor.execute(sql) value, attrs = cursor.fetchall()[0] but the query is more complicated. Based on the request returns
return JsonResponse({'data': response}) In two different calls to get_stats , different parameters should be passed (but the request object is originally the same, that’s the problem for me) and you should get different results. Another solution is to slightly change the logic of get_stats , instead of get_stats use another function. This solution has already been applied and is working. But it seems to me that it is more logical and easier to redefine the request object, which is passed as a parameter to the get_stats function, if possible.
And so the question is exactly this - is it possible to make a new request based on the received? Will this be right and good? If not, what is the right thing to do in my case?
data2to the requesteddata2function with the body<WSGIRequest: GET '/compare?type=transit>, I will be grateful. And then one does not understand what the difficulty is, while others do not know how to do it. - Mae