[Python] Django View Only Returns JSON Instead of Rendering Template

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    In my Django views.py, I have a function that is supposed to both render a website and return a JsonResponse. Normally, when I visit the URL, I expect to see the rendered website. However, instead of rendering the template, the only thing I see is the JSON response.

    def chatbot(request):
    if request.method == 'POST':
    message = request.POST.get('message')
    response = 'hi hi hi'
    print(message)
    return JsonResponse({'message': message, 'response':response})
    return render(request, 'chatbot.html',{'response':response})


    Web site output: web site output

    Continue reading...

Compartilhe esta Página