我试图从几个月前制作的项目中导入函数,但出现此错误:ModuleNotFoundError:没有名为“seleniumtrack”的模块
我尝试了 ChatGPT 推荐的一些东西,并尝试在互联网上查找内容,但不幸的是它不起作用。
这就是我的文件的排序方式: Python/ ├── seleniumtrack.py └── 曲目列表/ ├── 管理.py └── 下载器/ └── 视图.py 我正在尝试学习 Django,但这是我的views.py 脚本:
from django.shortcuts import render
from django import forms
from django.http import HttpResponseRedirect
from django.urls import reverse
import seleniumtrack
class SearchTracklist(forms.Form):
url = forms.CharField(label="Tracklist url")
class StartScraping(forms.Form):
start = forms.CharField(widget=forms.HiddenInput(), initial="start")
# Create your views here.
def index(request):
if "urls" not in request.session:
request.session["urls"] = []
if request.method == "POST":
form = StartScraping(request.POST)
if form.is_valid():
for url in request.session["urls"]:
seleniumtrack.scrape(url)
else:
return render(request, "tracklist/index.html", {
"form": form
})
return render(request, "tracklist/index.html", {
"urls": request.session["urls"]
})
def add(request):
if request.method == "POST":
form = SearchTracklist(request.POST)
if form.is_valid():
url = form.cleaned_data["url"]
request.session["urls"] += [url]
return HttpResponseRedirect(reverse("downloader:index"))
else:
return render(request, "tracklist/index.html", {
"form": form
})
return render(request, "tracklist/add.html", {
"form": SearchTracklist()
})
有人可以帮忙吗?
导入函数需要输入完整路径,seleniumtrack函数是在python文件夹内的seleniumtrack.py文件中吗?那么你需要调用这样的函数“from python.seleniumtrack import seleniumtrack”