18π
If you are using class based views :
POST provides data in request.data and GET in request.query_params
If you are using function based views:
request.data will do the work for both methods.
axios does not support sending params as body with get method , it will append params in url. so if you are using axios you will have to use query_params
Axios example code:
axios.get(API_URL, {
params: {
testData: 'test data',
pageNum: 1
}
})
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err.response.data);
});
DRF example code:
Class TestView(APIView):
def get(self, request):
test_data_var = request.query_params['testData']
page_num_var = request.query_params['pageNum']
Note:
If youβre testing it in postman then put the get request query params in Params tab.
0π
For me the accepted answer did not work.
A much simplier solution I saw no one mention is the following :
Append them to the URL like this : yourApi.com/subdomain/?parameter1=something
Axios.js
const target = "someApiYouWantToFetch.com"
let parameter = "DataYouWantToSend"
axios.get(`${target}?parameter=${parameter }`)
views.py
def get(self,request,*args,**kwargs): #or def list()
data = request.GET.get('name')
- 413 Payload Too Large on Django server
- Django TransactionManagementError when using signals
- Django Rest Framework: `get_serializer_class` called several times, with wrong value of request method
- Django: Implementing a referral program
- Set global minimum logging level across all loggers in Python/Django
0π
In DRF if you want to access request.GET you should use request.request.GET
for example
@action(methods=['GET',], detail=False)
def activation(request, *args, **kwargs):
uid = request.request.GET.get('uid')
token = request.request.GET.get('token')
- Django ajax error response best practice
- How can I create a partial search filter in Django REST framework?
- Systemctl strange error: Invalid arguments