django: return string from view

If you create a chat-bot or need this response on post request for confirmation - you should add decorator, otherwise Django block post requests. More info you can find here https://docs.djangoproject.com/en/2.1/ref/csrf/

Also in my case I had to add content_type="text/plain".

from django.views.decorators.csrf import csrf_protect
from django.http import HttpResponse
@csrf_exempt
def Index(request):
    return HttpResponse("Hello World", content_type="text/plain")

According to the documentation:

A view function, or view for short, is simply a Python function that takes a Web request and returns a Web response.

Each view function is responsible for returning an HttpResponse object.

In other words, your view should return a HttpResponse instance:

from django.http import HttpResponse

def myview(request):
    return HttpResponse("return this string")