1👍
✅
print
returns None
, regardless what you are priting, so you are printing the random choice, and then random_number
will be assigned None
, and then you return a HTTP response with None
. You thus should assign the outcome of the random choice to random_number
and then both print it and return it as a HTTP reponse:
from django.http import HttpResponse
import random
def number(request):
number = ['1', '2', '3',]
random_number = random.choice(number)
print(random_number)
return HttpResponse(random_number)
Source:stackexchange.com