Django 项目找不到数据库

最近学习Django,但是生成的数据库在视图调用时提示找不到?但是在数据库中确实能看到生成迁移的数据表

#views.py
def index(request):
    type_list = Product.objects.values('type').distinct()
    name_list = Product.objects.values('name', 'type')
    context = {'title': '首页', 'type_list': type_list, 'name_list': name_list}
    return render(request, 'index.html', context=context, status=200)

img

在你的views.py是否已导入了模型文件models.py

已解决:
要在views中导入表
方法如下: 其中index是app名称,根据自己的项目指定

from index.models import Product

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632