Reputation: 1
I am trying to call a view from a JavaScript file using Ajax, but i want the view to return only a value called "this". But when I do this, It throws an error saying view didn't return an HttpResponse object, it returned None instead.
Is it possible to just return a value from a view instead without a Html page?
Upvotes: 0
Views: 1581
Reputation: 3340
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 your code, you just return a value instead of HttpResponse
. The correct code would be :
from django.http import HttpResponse
def result(request):
if request=="POST":
return HttpResponse("something you want to view")
Upvotes: 1
Reputation: 26871
I don't know what the runAreaReview(param)
is supposed to return, but assuming it would return a string for example, then this should work:
from django.http import HttpResponse
def result(request):
param = ...
this = ...'
return HttpResponse( this )
Upvotes: 0