Home > Back-end >  keep getting error: ModuleNotFoundError: No module named 'requests' when i have requests i
keep getting error: ModuleNotFoundError: No module named 'requests' when i have requests i

Time:02-20

i have python installed but i keep seeing the below error when i try to import requests.

  File "/x/y/z/views.py", line 3, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

here is what my code looks like:

from django.shortcuts import render
from django.http import HttpResponse
import requests

def say_hello(request):
    return render(requests, 'hello.html')

apologies in advance if this is a dumb question, i have just started to learn django.

CodePudding user response:

I think you misunderstand what request does here. The render function requires a request object which is already being passed down from your function parameters. So instead of trying to call an unrelated library, you should be using the request object that you are passing through your function parameter to the render function. Try this:

from django.shortcuts import render

def say_hello(request):   # You pass this request object to the render function
    return render(request, 'hello.html')
  • Related