[Python] Trying to send basic string to Django Backend via POST request using axios but no...

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I've been trying a basic string to Django backend from frontend using axios.post call.

    Connection is ensured and backend side detects the request but the data is empty.

    Frontend side:

    const axios = Axios.create({
    baseURL: API_URL,
    headers: {
    'Content-Type': 'application/json',
    },
    });

    export class MessageService {
    static async sendMessage(message: string): Promise<any> {
    try {
    const data = {question: message}
    // Uncomment the line below to use the actual API call
    const response = await axios.post('/chatbot/rest_handler', data);

    return response;
    } catch (error) {
    console.error('Error sending message:', error);
    throw error;
    }
    }


    Backend side:

    @csrf_exempt
    def rest_handler(request):
    print("REQUEST IS SENT FROM FRONTEND")
    req_data = request.body
    q_info = req_data.decode("utf-8")
    print("QUESTION:"+ q_info)
    return JsonResponse(request)


    But in the output screen, I see an empty string:

    [09/Jun/2025 10:49:33] "OPTIONS /chatbot/rest_handler HTTP/1.1" 200 2
    REQUEST IS SENT FROM FRONTEND
    QUESTION:

    Continue reading...

Compartilhe esta Página