[Answered ]-How can I send React variable to Django view?

1👍

In the view

def get_lists(request):
   print(request.query_params['id_list']) # 'id_list being the variable you want to pass from the front end

this sets that we are expecting a parameter from the front end get request.
Remember to add a try catch arround it..cos if that query_param doesnt exist it will throw and erroe.

Non in the FE.. while making a request, set request parameter ‘id_list = ‘


var url = new URL('http://127.0.0.1:8000/lists')

var params = {id_list:'3'} // or whatever the params

url.search = new URLSearchParams(params).toString();

fetch(url);

Essentially you add the query params to the request url like

http://127.0.0.1:8000/lists/?id_list=3&another_param=2..

test the backend using postman or smthn before integration..to make sure the correct url and stuff.

Leave a comment