keep getting error: ModuleNotFoundError: No module named 'requests' when i have requests installed
keep getting error: ModuleNotFoundError: No module named 'requests' when i have requests installed
我已经安装了 python,但是当我尝试导入请求时,我一直看到以下错误。
File "/x/y/z/views.py", line 3, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
我的代码如下所示:
from django.shortcuts import render
from django.http import HttpResponse
import requests
def say_hello(request):
return render(requests, 'hello.html')
如果这是一个愚蠢的问题,请提前致歉,我刚刚开始学习 django。
我认为您误解了请求在这里的作用。 render
函数需要一个 request
对象,该对象已从您的函数参数中传递下来。因此,与其尝试调用不相关的库,不如使用通过函数参数传递给 render
函数的请求对象。试试这个:
from django.shortcuts import render
def say_hello(request): # You pass this request object to the render function
return render(request, 'hello.html')
我已经安装了 python,但是当我尝试导入请求时,我一直看到以下错误。
File "/x/y/z/views.py", line 3, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
我的代码如下所示:
from django.shortcuts import render
from django.http import HttpResponse
import requests
def say_hello(request):
return render(requests, 'hello.html')
如果这是一个愚蠢的问题,请提前致歉,我刚刚开始学习 django。
我认为您误解了请求在这里的作用。 render
函数需要一个 request
对象,该对象已从您的函数参数中传递下来。因此,与其尝试调用不相关的库,不如使用通过函数参数传递给 render
函数的请求对象。试试这个:
from django.shortcuts import render
def say_hello(request): # You pass this request object to the render function
return render(request, 'hello.html')