I have issue with retrieving data from POST in my django view. I send React form values with axios to my django backend. I believe data gets put into POST but somehow it seems that there isn't any data in POST and i can't access it in my django view. What could be issue here? (I can also see in my console that values are successfully submitted)
Source code:
Django views.py:
@csrf_exempt
def send(request):
if request.method == "POST":
data = request.body('name')
send_mail('Test 1', data, 'austin.milk1@gmail.com', ['lowoko9513@gomail4.com',], fail_silently=False)
return redirect('/api/')
React form handling:
handleFormSubmit = (event) => {
const name = event.target.elements.name.value;
const email = event.target.elements.email.value;
event.preventDefault();
axios.post('http://127.0.0.1:8000/api/send', {
name: name,
email: email
})
.then(res => console.log(res))
.catch(error => console.err(error));
};
New error:
File "C:\Users\austi\PycharmProjects\Fitex#1\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\austi\PycharmProjects\Fitex#1\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\austi\PycharmProjects\Fitex#1\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\austi\PycharmProjects\Fitex#1\venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\austi\PycharmProjects\Fitex5\backend\src\training\api\views.py", line 78, in send
data = request.body('name')
TypeError: 'bytes' object is not callable